[parted-devel] [PATCH v2] libparted: Fix memory leaks

Brian C. Lane bcl at redhat.com
Mon Aug 3 23:34:15 UTC 2015


On Mon, Aug 03, 2015 at 11:46:33AM +0300, Amarnath Valluri wrote:
> * libparted/fs/r/hfs/hfs.c(hfsplus_resize): Don't leak embedded_geom
>   when volume resizing failed.
> * libparted/fs/fat/fat.c(fat_create): Don't leake fs in-case of
>   fat_write_clustor failuer.
> * libparted/arch/linux.c(_kernel_get_partition_start_and_length): Don't leak
>   dev_fd file descriptor.
> 
> Signed-off-by: Amarnath Valluri <amarnath.valluri at intel.com>
> ---
>  libparted/arch/linux.c   | 1 +
>  libparted/fs/r/fat/fat.c | 2 +-
>  libparted/fs/r/hfs/hfs.c | 1 +
>  3 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
> index 27bbb80..349442b 100644
> --- a/libparted/arch/linux.c
> +++ b/libparted/arch/linux.c
> @@ -2665,6 +2665,7 @@ _kernel_get_partition_start_and_length(PedPartition const *part,
>                  int dev_fd = open (dev_name, O_RDONLY);
>                  if (dev_fd != -1 && ioctl (dev_fd, HDIO_GETGEO, &geom)) {
>                          *start = geom.start;
> +                        close (dev_fd);
>                          ok = true;
>                  } else {
>                          if (dev_fd != -1)
> diff --git a/libparted/fs/r/fat/fat.c b/libparted/fs/r/fat/fat.c
> index 5aa72d8..4ecf5c5 100644
> --- a/libparted/fs/r/fat/fat.c
> +++ b/libparted/fs/r/fat/fat.c
> @@ -305,7 +305,7 @@ fat_create (PedGeometry* geom, FatType fat_type, PedTimer* timer)
>  		memset (fs_info->buffer, 0, fs_info->cluster_size);
>  		if (!fat_write_cluster (fs, fs_info->buffer,
>  					fs_info->root_cluster))
> -			return 0;
> +			goto error_free_buffers;
>  	}
>  
>  	fs_info->serial_number = generate_random_uint32 ();
> diff --git a/libparted/fs/r/hfs/hfs.c b/libparted/fs/r/hfs/hfs.c
> index a1c37cc..7109a45 100644
> --- a/libparted/fs/r/hfs/hfs.c
> +++ b/libparted/fs/r/hfs/hfs.c
> @@ -985,6 +985,7 @@ hfsplus_resize (PedFileSystem* fs, PedGeometry* geom, PedTimer* timer)
>  	/* Resize the HFS+ volume */
>  	if (!hfsplus_volume_resize (fs, embedded_geom, timer_plus)) {
>  		if (timer_plus != timer) ped_timer_destroy_nested (timer_plus);
> +		if (priv_data->wrapper) ped_geometry_destroy (embedded_geom);
>  		ped_exception_throw (
>  			PED_EXCEPTION_ERROR,
>  			PED_EXCEPTION_CANCEL,
> -- 
> 1.9.1

Thanks, that looks good.

-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)



More information about the parted-devel mailing list