Skip to contentSkip to conversation

staging: greybus: loopback_test: fix device-name leak

PATCH In review Gargi Sharma 2 participants 2 messages Feb 22, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 staging: greybus: loopback_test: fix device-name leak

All the device names were being always leaked. Also, illegal free was being called upon namelist[n] which was coincidentally NULL. The pointer to dirent structures must be individually freed before freeing the pointer array.

Coccinelle Script:
@@
expression arr,ex1,ex2;
@@

for(ex1 = 0; ex1 < ex2; ex1++) { <...
arr[
- ex2
+ ex1
]
...> }

Reviewed by: Johan Hovold <[email protected]>
---
Changes in v4:
-Fixed subject line, added reviewed by tag.
Changes in v3:
-Edited the commit message.
Changes in v2:
-Made the commit message clearer.

---
 drivers/staging/greybus/tools/loopback_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/tools/loopback_test.c +1 -1
index 18d7a3d..1c01833 100644
@@ -636,7 +636,7 @@ int find_loopback_devices(struct loopback_test *t)
 	ret = 0;
 done:
 	for (i = 0; i < n; i++)
-		free(namelist[n]);
+		free(namelist[i]);
 	free(namelist);
 baddir:
 	return ret;
Signature · 1 line
2.7.4
Acked-by on v4 1/1
#1 lore raw
Quoted 17 lines · Gargi Sharma

All the device names were being always leaked. Also, illegal free was being called upon namelist[n] which was coincidentally NULL. The pointer to dirent structures must be individually freed before freeing the pointer array.

Coccinelle Script:
@@
expression arr,ex1,ex2;
@@

for(ex1 = 0; ex1 < ex2; ex1++) { <...
arr[
- ex2
+ ex1
]
...> }

Quoted 2 lines

Reviewed by: Johan Hovold <[email protected]>

Quoted 34 lines

---
Changes in v4:
-Fixed subject line, added reviewed by tag.
Changes in v3:
-Edited the commit message.
Changes in v2:
-Made the commit message clearer.

---
 drivers/staging/greybus/tools/loopback_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/greybus/tools/loopback_test.c +1 -2
index 18d7a3d..1c01833 100644
@@ -636,7 +636,7 @@ int find_loopback_devices(struct loopback_test *t)
 	ret = 0;
 done:
 	for (i = 0; i < n; i++)
-		free(namelist[n]);
+		free(namelist[i]);
 	free(namelist);
 baddir:
 	return ret;
--

2.7.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1487777901-8577-1-git-send-email-gs051095%40gmail.com.
For more options, visit https://groups.google.com/d/optout.