From 5d3a5d81fbc3fe4a6ba7d64337da110eb2791e25 Mon Sep 17 00:00:00 2001 From: Vivek Trivedi Date: Mon, 21 Dec 2015 10:54:37 +1100 Subject: [PATCH] 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 --- io/imap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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; } -- 2.47.2