devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] convert-dtsv0-lexer.l: fix memory leak
@ 2016-07-12 22:35 Jean-Christophe Dubois
       [not found] ` <1468362950-32027-1-git-send-email-jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Jean-Christophe Dubois @ 2016-07-12 22:35 UTC (permalink / raw)
  To: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA,
	david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+, jdl-CYoMK+44s/E
  Cc: Jean-Christophe Dubois

CID 132822 (#1 of 1): Resource leak (RESOURCE_LEAK)
9. leaked_storage: Variable newname going out of scope leaks the storage it points to

Signed-off-by: Jean-Christophe Dubois <jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org>
---
 convert-dtsv0-lexer.l | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/convert-dtsv0-lexer.l b/convert-dtsv0-lexer.l
index 259e527..8d8289b 100644
--- a/convert-dtsv0-lexer.l
+++ b/convert-dtsv0-lexer.l
@@ -208,6 +208,12 @@ static void convert_file(const char *fname)
 	char *newname;
 
 	newname = xmalloc(len + sizeof(suffix));
+
+	if (!newname) {
+		die("failed to allocate memory for input file %s: %s\n",
+		    fname, strerror(errno));
+	}
+
 	memcpy(newname, fname, len);
 	memcpy(newname + len, suffix, sizeof(suffix));
 
@@ -223,6 +229,8 @@ static void convert_file(const char *fname)
 
 	while(yylex())
 		;
+
+	free(newname);
 }
 
 int main(int argc, char *argv[])
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-07-23 14:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-12 22:35 [PATCH] convert-dtsv0-lexer.l: fix memory leak Jean-Christophe Dubois
     [not found] ` <1468362950-32027-1-git-send-email-jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org>
2016-07-13  2:04   ` David Gibson
     [not found]     ` <20160713020446.GC14615-RXTfZT5YzpxwFLYp8hBm2A@public.gmane.org>
2016-07-13  6:02       ` Jean-Christophe DUBOIS
     [not found]         ` <5785D973.7090108-WBS85hRCVJbxB9160cZjhg@public.gmane.org>
2016-07-23 14:51           ` David Gibson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).