devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Jean-Christophe Dubois <jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org>
Cc: devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	jdl-CYoMK+44s/E@public.gmane.org
Subject: Re: [PATCH] convert-dtsv0-lexer.l: fix memory leak
Date: Wed, 13 Jul 2016 12:04:46 +1000	[thread overview]
Message-ID: <20160713020446.GC14615@voom.fritz.box> (raw)
In-Reply-To: <1468362950-32027-1-git-send-email-jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 1364 bytes --]

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-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));
> +	}
> +

This hunk is unnecessary.  xmalloc() already die()s rather than failing.

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

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  parent reply	other threads:[~2016-07-13  2:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
     [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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160713020446.GC14615@voom.fritz.box \
    --to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=jcd-WBS85hRCVJbxB9160cZjhg@public.gmane.org \
    --cc=jdl-CYoMK+44s/E@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).