aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-09-08 08:51:45 -0500
committerRob Landley <rob@landley.net>2014-09-08 08:51:45 -0500
commit3edbb571ab5ba1d0c177d5b9bee6c67f021ed06a (patch)
tree88bd9ad878394432b2f0379e53d4e07ed328dc9f
parent12eff430e9d20c62fa9cc81d0b6ecface61bac18 (diff)
downloadtoybox-3edbb571ab5ba1d0c177d5b9bee6c67f021ed06a.tar.gz
Fix more memory leaks reported by Ashwini Sharma.
-rw-r--r--toys/posix/cpio.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/toys/posix/cpio.c b/toys/posix/cpio.c
index 668f2ee9..39fd9c33 100644
--- a/toys/posix/cpio.c
+++ b/toys/posix/cpio.c
@@ -94,7 +94,10 @@ void cpio_main(void)
// Read header and name.
xreadall(afd, toybuf, 110);
tofree = name = strpad(afd, x8u(toybuf+94), 110);
- if (!strcmp("TRAILER!!!", name)) break;
+ if (!strcmp("TRAILER!!!", name)) {
+ if (CFG_TOYBOX_FREE) free(tofree);
+ break;
+ }
// If you want to extract absolute paths, "cd /" and run cpio.
while (*name == '/') name++;
@@ -121,6 +124,7 @@ void cpio_main(void)
} else if (S_ISLNK(mode)) {
data = strpad(afd, size, 0);
if (!test) err = symlink(data, name);
+ free(data);
// Can't get a filehandle to a symlink, so do special chown
if (!err && !getpid()) err = lchown(name, uid, gid);
} else if (S_ISREG(mode)) {
@@ -249,4 +253,5 @@ void cpio_main(void)
xwrite(afd, toybuf,
sprintf(toybuf, "070701%040X%056X%08XTRAILER!!!", 1, 0x0b, 0)+4);
}
+ if (TT.archive) xclose(afd);
}