From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lukasz Majewski Date: Mon, 30 Nov 2015 14:51:09 +0100 Subject: [U-Boot] [PATCH] dfu: fix possible memory leak in dfu_init_env_entities() In-Reply-To: <1448292214-10787-1-git-send-email-p.marczak@samsung.com> References: <1448292214-10787-1-git-send-email-p.marczak@samsung.com> Message-ID: <20151130145109.0049de15@amdc2363> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 > Cc: Lukasz Majewski > --- > 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