xfs
[Top] [All Lists]

Re: [PATCH v2 1/4] xfsprogs: xfs_io: fix a memory leak in imap_f

To: Vivek Trivedi <t.vivek@xxxxxxxxxxx>
Subject: Re: [PATCH v2 1/4] xfsprogs: xfs_io: fix a memory leak in imap_f
From: Christoph Hellwig <hch@xxxxxxxxxxxxx>
Date: Sun, 20 Dec 2015 07:33:57 -0800
Cc: xfs@xxxxxxxxxxx, a.sahrawat@xxxxxxxxxxx, pankaj.m@xxxxxxxxxxx
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1449832143-26356-2-git-send-email-t.vivek@xxxxxxxxxxx>
References: <1449832143-26356-1-git-send-email-t.vivek@xxxxxxxxxxx> <1449832143-26356-2-git-send-email-t.vivek@xxxxxxxxxxx>
User-agent: Mutt/1.5.23 (2014-03-12)
> @@ -39,6 +39,8 @@ imap_f(int argc, char **argv)
> -             if (count == 0)
> +             if (count == 0) {
> +                     free(t);
>                       return 0;
> +             }

please use a goto out_free; here

>
>               for (i = 0; i < count; i++) {
>                       printf(_("ino %10llu count %2d mask %016llx\n"),
>                               (unsigned long long)t[i].xi_startino,
> @@ -55,6 +59,7 @@ imap_f(int argc, char **argv)
>                               (unsigned long long)t[i].xi_allocmask);
>               }
>       }
> +     free(t);
>       perror("xfsctl(XFS_IOC_FSINUMBERS)");
>       exitcode = 1;
>       return 0;

and place the free just before the return here so that we have a single
uwinding exit.

Otherwise this looks good to me.

<Prev in Thread] Current Thread [Next in Thread>