]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io: fix a memory leak in imap_f
authorVivek Trivedi <t.vivek@samsung.com>
Sun, 20 Dec 2015 23:54:37 +0000 (10:54 +1100)
committerDave Chinner <david@fromorbit.com>
Sun, 20 Dec 2015 23:54:37 +0000 (10:54 +1100)
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 <t.vivek@samsung.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
io/imap.c

index 34901cb9dc44fd8c9dfb2a746f449e2004baf3ab..7123432f411f8f895db1f6aaa9df18e3cbb61ed4 100644 (file)
--- 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;
 }