Skip to contentSkip to conversation

staging: dgap: fix memory leak in dgap_parsefile()

PATCH In review Daeseok Youn 1 participant 1 message Jul 15, 2014 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v2 8/8 staging: dgap: fix memory leak in dgap_parsefile()

The p->u.board.status is allocated and set a string as "No" once within allocating a node of BNODE type. But it also set again with kstrdup() in case of "STATUS" or "ID". So just free this buffer and allocate again with kstrdup().

---
V2: just use kfree for buffers which assigned to newly value
and then allocate again properly.

 drivers/staging/dgap/dgap.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/staging/dgap/dgap.c +3 -0
index e4ea68b..76503fe 100644
@@ -6599,6 +6599,8 @@ static int dgap_parsefile(char **in)
 				pr_err("parse: unexpected end of file\n");
 				return -1;
 			}
+
+			kfree(p->u.board.status);
 			p->u.board.status = kstrdup(s, GFP_KERNEL);
 			break;
 
@@ -6649,6 +6651,7 @@ static int dgap_parsefile(char **in)
 				return -1;
 			}
 
+			kfree(p->u.board.status);
 			p->u.board.status = kstrdup(s, GFP_KERNEL);
 
 			if (p->type == CNODE) {
Signature · 1 line
1.7.1