Re: [PATCH] convert-dtsv0-lexer.l: fix memory leak

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



Le 13/07/2016 04:04, David Gibson a écrit :
On Wed, Jul 13, 2016 at 12:35:50AM +0200, Jean-Christophe Dubois wrote:
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@xxxxxxxxxxxxxxx>
---
  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));
+	}
+
This hunk is unnecessary.  xmalloc() already die()s rather than failing.
OK.

On a correctness point of view there is still the "free" to be done (see below).

  	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[])

--
To unsubscribe from this list: send the line "unsubscribe devicetree-compiler" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux