[PATCH 07/10] btrfs-progs: fix memory leak on error path

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

 



dev_scans and t_scans should be freed on malloc error.

Signed-off-by: Eryu Guan <guaneryu@xxxxxxxxx>
---
 chunk-recover.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/chunk-recover.c b/chunk-recover.c
index 1fb04f7..c727f0f 100644
--- a/chunk-recover.c
+++ b/chunk-recover.c
@@ -847,11 +847,16 @@ static int scan_devices(struct recover_control *rc)
 	if (!dev_scans)
 		return -ENOMEM;
 	t_scans = (pthread_t *)malloc(sizeof(pthread_t) * devnr);
-	if (!t_scans)
+	if (!t_scans) {
+		free(dev_scans);
 		return -ENOMEM;
+	}
 	t_rets = (long *)malloc(sizeof(long) * devnr);
-	if (!t_rets)
+	if (!t_rets) {
+		free(dev_scans);
+		free(t_scans);
 		return -ENOMEM;
+	}
 
 	list_for_each_entry(dev, &rc->fs_devices->devices, dev_list) {
 		fd = open(dev->name, O_RDONLY);
-- 
2.4.3

--
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