diff mbox series

thermal/core: avoid memory leak

Message ID 20210322191204.GA2122573@LEGION (mailing list archive)
State Superseded, archived
Headers show
Series thermal/core: avoid memory leak | expand

Commit Message

Muhammad Usama Anjum March 22, 2021, 7:12 p.m. UTC
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.

Signed-off-by: Muhammad Usama Anjum <musamaanjum@gmail.com>
---
 drivers/thermal/thermal_core.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Dan Carpenter March 22, 2021, 7:18 p.m. UTC | #1
On Tue, Mar 23, 2021 at 12:12:04AM +0500, Muhammad Usama Anjum wrote:
> 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
Muhammad Usama Anjum March 22, 2021, 7:19 p.m. UTC | #2
On Mon, 2021-03-22 at 22:18 +0300, Dan Carpenter wrote:
> On Tue, Mar 23, 2021 at 12:12:04AM +0500, Muhammad Usama Anjum wrote:
> > 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
> regards,
> dan carpenter
>
diff mbox series

Patch

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index c8d4010940ef..3566fd291399 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -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);
 }