Re: [PATCH 01/11] xfsprogs: xfs_io: fix a memory leak in imap_f

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 12/2/15 5:19 AM, Vivek Trivedi wrote:
> add NULL check for malloc return and free allocated memory in
> return path in imap_f
> 
> Signed-off-by: Vivek Trivedi <t.vivek@xxxxxxxxxxx>

Reviewed-by: Eric Sandeen <sandeen@xxxxxxxxxx>

> ---
>  io/imap.c |    7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/io/imap.c b/io/imap.c
> index 34901cb..6ed98eb 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;
> @@ -46,8 +48,10 @@ imap_f(int argc, char **argv)
>  	bulkreq.ocount  = &count;
>  
>  	while (xfsctl(file->name, file->fd, XFS_IOC_FSINUMBERS, &bulkreq) == 0) {
> -		if (count == 0)
> +		if (count == 0) {
> +			free(t);
>  			return 0;
> +		}
>  		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;
> 

_______________________________________________
xfs mailing list
xfs@xxxxxxxxxxx
http://oss.sgi.com/mailman/listinfo/xfs



[Index of Archives]     [Linux XFS Devel]     [Linux Filesystem Development]     [Filesystem Testing]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux