Re: [PATCH] btrfs-progs: mkfs seg fault for wrong free

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

 



On Thu, Apr 25, 2013 at 08:15:42PM +0800, Anand Jain wrote:
> --- a/disk-io.c
> +++ b/disk-io.c
> @@ -1290,8 +1290,10 @@ static int close_all_devices(struct btrfs_fs_info *fs_info)
>  				fprintf(stderr, "Warning, could not drop caches\n");
>  		}
>  		close(device->fd);
> -		kfree(device->name);
> -		kfree(device->label);
> +		if (device->name)
> +			kfree(device->name);
> +		if (device->label)
> +			kfree(device->label);

As we're going to use the kernel sources directly, we should also keep
the semantics of the helpers. The in-kernel kfree accepts NULL and does
nothing in that case, so should the userspace replacement which is now
implemented as:

#define kfree(x) free(x)

>  		kfree(device);
>  	}
>  	kfree(fs_info->fs_devices);
> diff --git a/utils.c b/utils.c
> index 7b028a7..8104465 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -484,6 +484,8 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans,
>  	device = kmalloc(sizeof(*device), GFP_NOFS);
>  	if (!device)
>  		return -ENOMEM;
> +	memset(device, 0, sizeof(*device));

Please replace the above kmalloc with kzalloc instead.

> +	
>  	buf = kmalloc(sectorsize, GFP_NOFS);
>  	if (!buf) {
>  		kfree(device);
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




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

  Powered by Linux