From eeec209467bbfbf6d6bd138246e1c8d184b4c817 Mon Sep 17 00:00:00 2001 From: Simo Piiroinen Date: Thu, 10 Dec 2020 13:55:25 +0200 Subject: fcopy: Fix memory leaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These have little consequences as the tool exits anyway, but fs_copydir() leaks memory on success path and check() on failure path. Signed-off-by: Simo Piiroinen Signed-off-by: Tomi Leppänen --- src/fcopy/main.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/fcopy/main.c') diff --git a/src/fcopy/main.c b/src/fcopy/main.c index a41df52a1..d863b537b 100644 --- a/src/fcopy/main.c +++ b/src/fcopy/main.c @@ -268,16 +268,14 @@ static int fs_copydir(const char *infname, const struct stat *st, int ftype, str first = 0; else if (!arg_quiet) fprintf(stderr, "Warning fcopy: skipping %s, file already present\n", infname); - free(outfname); - return 0; + goto out; } // extract mode and ownership if (stat(infname, &s) != 0) { if (!arg_quiet) fprintf(stderr, "Warning fcopy: skipping %s, cannot find inode\n", infname); - free(outfname); - return 0; + goto out; } uid_t uid = s.st_uid; gid_t gid = s.st_gid; @@ -287,8 +285,7 @@ static int fs_copydir(const char *infname, const struct stat *st, int ftype, str if ((s.st_size + size_cnt) > copy_limit) { fprintf(stderr, "Error fcopy: size limit of %lu MB reached\n", (copy_limit / 1024) / 1024); size_limit_reached = 1; - free(outfname); - return 0; + goto out; } file_cnt++; @@ -303,7 +300,8 @@ static int fs_copydir(const char *infname, const struct stat *st, int ftype, str else if (ftype == FTW_SL) { copy_link(infname, outfname, mode, uid, gid); } - +out: + free(outfname); return(0); } @@ -336,6 +334,7 @@ static char *check(const char *src) { return rsrc; // normal exit from the function errexit: + free(rsrc); fprintf(stderr, "Error fcopy: invalid file %s\n", src); exit(1); } -- cgit v1.2.3-70-g09d2