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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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". If it is not allocated yet, use kstrdup().
If not, use just memcpy().

Signed-off-by: Daeseok Youn <daeseok.youn@xxxxxxxxx>
---
 drivers/staging/dgap/dgap.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index a207bd7..cedf4b3 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -6598,7 +6598,11 @@ static int dgap_parsefile(char **in)
 				pr_err("dgap: parse: unexpected end of file\n");
 				return -1;
 			}
-			p->u.board.status = kstrdup(s, GFP_KERNEL);
+
+			if (p->u.board.status)
+				memcpy(p->u.board.status, s, strlen(s) + 1);
+			else
+				p->u.board.status = kstrdup(s, GFP_KERNEL);
 			break;
 
 		case NPORTS:	/* number of ports */
@@ -6648,7 +6652,10 @@ static int dgap_parsefile(char **in)
 				return -1;
 			}
 
-			p->u.board.status = kstrdup(s, GFP_KERNEL);
+			if (p->u.board.status)
+				memcpy(p->u.board.status, s, strlen(s) + 1);
+			else
+				p->u.board.status = kstrdup(s, GFP_KERNEL);
 
 			if (p->type == CNODE) {
 				p->u.conc.id = kstrdup(s, GFP_KERNEL);
-- 
1.7.1

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux