From: Vivek Trivedi Date: Sun, 20 Dec 2015 23:54:37 +0000 (+1100) Subject: xfs_io: fix a memory leak in imap_f X-Git-Tag: v4.5.0-rc1~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d3a5d81fbc3fe4a6ba7d64337da110eb2791e25;p=thirdparty%2Fxfsprogs-dev.git xfs_io: fix a memory leak in imap_f add NULL check for malloc return and free allocated memory in return path in imap_f [dchinner: changed to error stack] Signed-off-by: Vivek Trivedi Reviewed-by: Dave Chinner Signed-off-by: Dave Chinner --- diff --git a/io/imap.c b/io/imap.c index 34901cb9d..7123432f4 100644 --- a/io/imap.c +++ b/io/imap.c @@ -39,6 +39,8 @@ imap_f(int argc, char **argv) nent = atoi(argv[1]); t = malloc(nent * sizeof(*t)); + if (!t) + return 0; bulkreq.lastip = &last; bulkreq.icount = nent; @@ -47,7 +49,7 @@ imap_f(int argc, char **argv) while (xfsctl(file->name, file->fd, XFS_IOC_FSINUMBERS, &bulkreq) == 0) { if (count == 0) - return 0; + goto out_free; for (i = 0; i < count; i++) { printf(_("ino %10llu count %2d mask %016llx\n"), (unsigned long long)t[i].xi_startino, @@ -57,6 +59,8 @@ imap_f(int argc, char **argv) } perror("xfsctl(XFS_IOC_FSINUMBERS)"); exitcode = 1; +out_free: + free(t); return 0; }