Blob Blame History Raw
From bb1014e4e66c6a113f208d2ede8e484f7b702a9d Mon Sep 17 00:00:00 2001
From: Amarnath Valluri <amarnath.valluri@intel.com>
Date: Mon, 3 Aug 2015 11:46:33 +0300
Subject: [PATCH 16/18] libparted: Fix memory leaks

* 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@intel.com>
Signed-off-by: Brian C. Lane <bcl@redhat.com>
(cherry picked from commit b70ecd7a7ef1f69b0afd5c239681decbf369f5d9)
---
 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 1d4cf17..d33c02d 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -2655,6 +2655,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,
-- 
2.4.3