From: Eric Sandeen Date: Mon, 14 Apr 2014 06:12:03 +0000 (+1000) Subject: xfsprogs: trivial buffer frees on error paths X-Git-Tag: v3.2.0-rc1~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=355ac015260e16509e1b4f74eee1f4703ba733a9;p=thirdparty%2Fxfsprogs-dev.git xfsprogs: trivial buffer frees on error paths Lots of memory leaks on error paths etc, spotted by coverity. This patch rolls up the super-straightforward fixes across xfsprogs. Signed-off-by: Eric Sandeen Reviewed-by: Brian Foster Signed-off-by: Dave Chinner --- diff --git a/db/addr.c b/db/addr.c index f74dd628a..9bea1c7a0 100644 --- a/db/addr.c +++ b/db/addr.c @@ -85,16 +85,14 @@ addr_f( fl = flist_scan(argv[1]); if (fl == NULL) return 0; - if (!flist_parse(fld, fl, iocur_top->data, 0)) { - flist_free(fl); - return 0; - } + if (!flist_parse(fld, fl, iocur_top->data, 0)) + goto out; + flist_print(fl); for (tfl = fl; tfl->child != NULL; tfl = tfl->child) { if ((tfl->flags & FL_OKLOW) && tfl->low < tfl->high) { dbprintf(_("array not allowed for addr command\n")); - flist_free(fl); - return 0; + goto out; } } fld = tfl->fld; @@ -103,7 +101,7 @@ addr_f( next = inode_next_type(); if (next == TYP_NONE) { dbprintf(_("no next type for field %s\n"), fld->name); - return 0; + goto out; } fa = &ftattrtab[fld->ftyp]; ASSERT(fa->ftyp == fld->ftyp); @@ -111,9 +109,10 @@ addr_f( if (adf == NULL) { dbprintf(_("no addr function for field %s (type %s)\n"), fld->name, fa->name); - return 0; + goto out; } (*adf)(iocur_top->data, tfl->offset, next); +out: flist_free(fl); return 0; } diff --git a/db/check.c b/db/check.c index 486769866..baf7f9f65 100644 --- a/db/check.c +++ b/db/check.c @@ -1136,7 +1136,7 @@ blocktrash_f( } if (blocks == 0) { dbprintf(_("blocktrash: no matching blocks\n")); - return 0; + goto out; } if (!sopt) dbprintf(_("blocktrash: seed %u\n"), seed); @@ -1161,6 +1161,7 @@ blocktrash_f( } } } +out: xfree(lentab); return 0; } @@ -1907,6 +1908,7 @@ ncheck_f( break; default: dbprintf(_("bad option -%c for ncheck command\n"), c); + xfree(ilist); return 0; } } diff --git a/db/write.c b/db/write.c index 7b34fc006..ca8bd0fd1 100644 --- a/db/write.c +++ b/db/write.c @@ -233,6 +233,7 @@ bwrite_lrot( memcpy(hold_region, base, shift); memcpy(base, base+shift, len-shift); memcpy(base+(len-shift), hold_region, shift); + free(hold_region); } /* ARGSUSED */ @@ -265,6 +266,7 @@ bwrite_rrot( memcpy(hold_region, base+(len-shift), shift); memmove(base+shift, base, len-shift); memcpy(base, hold_region, shift); + free(hold_region); } /* ARGSUSED */ diff --git a/io/parent.c b/io/parent.c index 47faaa002..ca989e960 100644 --- a/io/parent.c +++ b/io/parent.c @@ -258,6 +258,8 @@ parent_check(void) if (!bstatbuf || !parentbuf) { fprintf(stderr, _("unable to allocate buffers: %s\n"), strerror(errno)); + free(bstatbuf); + free(parentbuf); return 1; } diff --git a/mkfs/proto.c b/mkfs/proto.c index b7e07618f..95583c90b 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -49,7 +49,7 @@ char * setup_proto( char *fname) { - char *buf; + char *buf = NULL; static char dflt[] = "d--755 0 0 $"; int fd; long size; @@ -85,6 +85,7 @@ setup_proto( out_fail: close(fd); + free(buf); exit(1); }