Skip to contentSkip to conversation

: Fix memory leak by freeing buf

PATCH In review Manjeet Pawar 2 participants 2 messages May 28, 2015 – Jun 1, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : Fix memory leak by freeing buf

From: Manjeet Pawar <[email protected]>
Subject: [PATCH] pan/ltp-pan.c: free buf before function return to avoid memory leak

This patch avoid memory leak by freeing the buf before the slurp() function return

---
 pan/ltp-pan.c |    1 +
 1 file changed, 1 insertion(+)
pan/ltp-pan.c +1 -0
index 4c1e9de..905ff89 100644
@@ -1279,6 +1279,7 @@ static char *slurp(char *file)
 	if (read(fd, buf, sbuf.st_size) != sbuf.st_size) {
 		fprintf(stderr, "pan(%s): slurp failed.  errno:%d  %s\n",
 			panname, errno, strerror(errno));
+		free(buf);
 		return NULL;
 	}
 	buf[sbuf.st_size] = '\0';
Signature · 8 lines
1.7.9.5


------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

Hi!
Looking at the code, ltp-pan exits if this function fails, so the danger of memory leak was not real here.

But it's better to fix the function, pushed, thanks.

Signature · 8 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list