[PATCH 4/5] find_disk_attached_hba: fix memleak

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

 



If disk_path = diskfd_to_devpath(), we need free(disk_path) before
return, otherwise there will be a memory leak

Signed-off-by: Wu Guanghao <wuguanghao3@xxxxxxxxxx>
---
 super-intel.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/super-intel.c b/super-intel.c
index ef21ffba..98fb63d5 100644
--- a/super-intel.c
+++ b/super-intel.c
@@ -700,8 +700,11 @@ static struct sys_dev* find_disk_attached_hba(int fd, const char *devname)
 		return 0;

 	for (elem = list; elem; elem = elem->next)
-		if (path_attached_to_hba(disk_path, elem->path))
+		if (path_attached_to_hba(disk_path, elem->path)) {
+			if (disk_path != devname)
+				free(disk_path);
 			return elem;
+		}

 	if (disk_path != devname)
 		free(disk_path);
-- 
2.27.0



[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux