Skip to contentSkip to conversation

dm mpath: fix memory leak for attached_handler_name

PATCH In review Yufen Yu 2 participants 2 messages Apr 27, 2019 – Apr 29, 2019 Device mapper

lore
Share & tools
lore

Yufen Yu

author
#0 lore raw

PATCH 1/1 dm mpath: fix memory leak for attached_handler_name

If multipath does not set flag MPATHF_RETAIN_ATTACHED_HW_HANDLER, parse_path() would forget to free attached_handler_name when successfully exit, resulting in memory leak.

---
 drivers/md/dm-mpath.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/md/dm-mpath.c +2 -0
index 00e738c1222f..850a7c637a88 100644
@@ -841,6 +841,8 @@ static int setup_scsi_dh(struct block_device *bdev, struct multipath *m,
 			m->hw_handler_name = *attached_handler_name;
 			*attached_handler_name = NULL;
 		}
+	} else {
+		kfree(*attached_handler_name);
 	}
 
 	if (m->hw_handler_name) {
Signature · 1 line
2.16.2.dirty
#1 lore raw
Quoted 3 lines · Yufen Yu

If multipath does not set flag MPATHF_RETAIN_ATTACHED_HW_HANDLER, parse_path() would forget to free attached_handler_name when successfully exit, resulting in memory leak.

I believe this should rather be done in parse_path(), as setup_scsi_dh() nullifies the pointer anyway when it "steals" it. I'll send a patch shortly.

Thanks,
Martin

Quoted 20 lines
---
 drivers/md/dm-mpath.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/md/dm-mpath.c +2 -0
index 00e738c1222f..850a7c637a88 100644
@@ -841,6 +841,8 @@ static int setup_scsi_dh(struct block_device
 *bdev, struct multipath *m,
 			m->hw_handler_name = *attached_handler_name;
 			*attached_handler_name = NULL;
 		}
+	} else {
+		kfree(*attached_handler_name);
 	}
 

if (m->hw_handler_name) {