Skip to contentSkip to conversation

staging: tidspbridge: fix memory leak

PATCH Superseded Kulikov Vasiliy 2 participants 2 messages Jul 30, 2010

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 7/9 staging: tidspbridge: fix memory leak

dbll_create() leaks pzl_target if target_obj is NULL. Call kzalloc() only if memory is used.

---
 drivers/staging/tidspbridge/pmgr/dbll.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/tidspbridge/pmgr/dbll.c +2 -2
index 3636aa3..86840ce 100644
@@ -247,9 +247,9 @@ int dbll_create(struct dbll_tar_obj **target_obj,
 	DBC_REQUIRE(pattrs != NULL);
 	DBC_REQUIRE(target_obj != NULL);
 
-	/* Allocate DBL target object */
-	pzl_target = kzalloc(sizeof(struct dbll_tar_obj), GFP_KERNEL);
 	if (target_obj != NULL) {
+		/* Allocate DBL target object */
+		pzl_target = kzalloc(sizeof(struct dbll_tar_obj), GFP_KERNEL);
 		if (pzl_target = NULL) {
 			*target_obj = NULL;
 			status = -ENOMEM;
Signature · 1 line
1.7.0.4
#1 lore raw

Kulikov Vasiliy had written, on 07/30/2010 06:09 AM, the following:

Quoted 14 lines

dbll_create() leaks pzl_target if target_obj is NULL. Call kzalloc() only if memory is used.

---
 drivers/staging/tidspbridge/pmgr/dbll.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/tidspbridge/pmgr/dbll.c +0 -0
index 3636aa3..86840ce 100644
@@ -247,9 +247,9 @@ int dbll_create(struct dbll_tar_obj **target_obj,
 	DBC_REQUIRE(pattrs != NULL);

drivers/staging/tidspbridge/pmgr/dbll.c int dbll_create(struct dbll_tar_obj **target_obj, · line 255

Quoted 10 lines
drivers/staging/tidspbridge/pmgr/dbll.c +2 -2
 	DBC_REQUIRE(target_obj != NULL);
 
-	/* Allocate DBL target object */
-	pzl_target = kzalloc(sizeof(struct dbll_tar_obj), GFP_KERNEL);
 	if (target_obj != NULL) {
+		/* Allocate DBL target object */
+		pzl_target = kzalloc(sizeof(struct dbll_tar_obj), GFP_KERNEL);
 		if (pzl_target = NULL) {
 			*target_obj = NULL;
 			status = -ENOMEM;

I would suggest to add a else branch for if (target_obj != NULL) adding a status =-ENOMEM if error.

Overall, I guess we need to kick out the DBC_REQUIRE usage.. it is misleading as it is active only when DEBUG macro is enabled!

Signature · 2 lines
Regards,
Nishanth Menon