public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Lukasz Majewski <l.majewski@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] dfu: fix possible memory leak in dfu_init_env_entities()
Date: Mon, 30 Nov 2015 14:51:09 +0100	[thread overview]
Message-ID: <20151130145109.0049de15@amdc2363> (raw)
In-Reply-To: <1448292214-10787-1-git-send-email-p.marczak@samsung.com>

Hi Przemyslaw,

> The string of environment variable $dfu_alt_info is duplicated
> by strdup() before parsing its content. The memory leak occurs,
> when dfu fails, because the duplicated variable is freed only
> on command success.
> 
> This simple fix allows calling free() always before the return.
> 
> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
> Cc: Lukasz Majewski <l.majewski@samsung.com>
> ---
>  drivers/dfu/dfu.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
> index 8f5915e..420631a 100644
> --- a/drivers/dfu/dfu.c
> +++ b/drivers/dfu/dfu.c
> @@ -66,13 +66,11 @@ int dfu_init_env_entities(char *interface, char
> *devstr) 
>  	env_bkp = strdup(str_env);
>  	ret = dfu_config_entities(env_bkp, interface, devstr);
> -	if (ret) {
> +	if (ret)
>  		error("DFU entities configuration failed!\n");
> -		return ret;
> -	}
>  
>  	free(env_bkp);
> -	return 0;
> +	return ret;
>  }
>  
>  static unsigned char *dfu_buf;

Applied to u-boot-dfu branch.

Tested at Odroid XU3 and Trats boards.

-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

      parent reply	other threads:[~2015-11-30 13:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-23 15:23 [U-Boot] [PATCH] dfu: fix possible memory leak in dfu_init_env_entities() Przemyslaw Marczak
2015-11-23 15:53 ` Tom Rini
2015-11-30 13:51 ` Lukasz Majewski [this message]

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=20151130145109.0049de15@amdc2363 \
    --to=l.majewski@samsung.com \
    --cc=u-boot@lists.denx.de \
    /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