Skip to contentSkip to conversation

thermal/core: avoid memory leak

PATCH Superseded Muhammad Usama Anjum 2 participants 3 messages Mar 22, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal/core: avoid memory leak

When memory allocation for cdev is successful but ida_simple_get fails, branch to out_kfree_cdev label happens and cdev isn't freed. There are other some other branches in which the memory can leaked. Fix it by freeing cdev.

---
 drivers/thermal/thermal_core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/thermal/thermal_core.c +1 -0
index c8d4010940ef..3566fd291399 100644
@@ -1017,6 +1017,7 @@ __thermal_cooling_device_register(struct device_node *np,
 out_ida_remove:
 	ida_simple_remove(&thermal_cdev_ida, cdev->id);
 out_kfree_cdev:
+	kfree(cdev);
 	return ERR_PTR(ret);
 }
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 5 lines · Muhammad Usama Anjum

When memory allocation for cdev is successful but ida_simple_get fails, branch to out_kfree_cdev label happens and cdev isn't freed. There are other some other branches in which the memory can leaked. Fix it by freeing cdev.

The patch is correct, but Daniel already sent a fix for it.

regards,
dan carpenter

#2 lore raw
Quoted 9 lines · Dan Carpenter
Quoted 5 lines · Muhammad Usama Anjum

When memory allocation for cdev is successful but ida_simple_get fails, branch to out_kfree_cdev label happens and cdev isn't freed. There are other some other branches in which the memory can leaked. Fix it by freeing cdev.

The patch is correct, but Daniel already sent a fix for it.

Got it. Thank you.

Thanks,
Usama

Quoted 3 lines

regards,
dan carpenter