fix: Avoid leaking all kinds of stuff in examples/pack
Apart from potentionally leaking malloced memory on error, which isn't too bad since we immediately exit afterwards, we were leaving all opened files dangling, as fclose() was never called.
This commit is contained in:
parent
73c4dce573
commit
ae7bf076dc
@ -47,6 +47,7 @@ int main(int argc, char** argv)
|
|||||||
if (!buf)
|
if (!buf)
|
||||||
{
|
{
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
|
fclose(fp);
|
||||||
exit_status = 1;
|
exit_status = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -54,8 +55,7 @@ int main(int argc, char** argv)
|
|||||||
if (ferror(fp))
|
if (ferror(fp))
|
||||||
{
|
{
|
||||||
perror("fread");
|
perror("fread");
|
||||||
exit_status = 1;
|
goto err;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
@ -63,8 +63,7 @@ int main(int argc, char** argv)
|
|||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
{
|
{
|
||||||
perror("fstat");
|
perror("fstat");
|
||||||
exit_status = 1;
|
goto err;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct minitar_entry_metadata metadata;
|
struct minitar_entry_metadata metadata;
|
||||||
@ -78,6 +77,7 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
rc = minitar_write_file_entry(&mp, &metadata, buf);
|
rc = minitar_write_file_entry(&mp, &metadata, buf);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
{
|
{
|
||||||
@ -87,6 +87,13 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
arg++;
|
arg++;
|
||||||
|
continue;
|
||||||
|
|
||||||
|
err:
|
||||||
|
free(buf);
|
||||||
|
fclose(fp);
|
||||||
|
exit_status = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
minitar_close_w(&mp);
|
minitar_close_w(&mp);
|
||||||
return exit_status;
|
return exit_status;
|
||||||
|
Loading…
Reference in New Issue
Block a user