dfu: fix possible memory leak in dfu_init_env_entities()
PATCH 1/1 dfu: fix possible memory leak in dfu_init_env_entities()
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.
--- drivers/dfu/dfu.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/dfu/dfu.c +2 -4
@@ -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;
Signature · 1 line
1.9.1
PATCH 1/1 dfu: fix possible memory leak in dfu_init_env_entities()
Quoted 9 lines · Przemyslaw Marczak
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 <[email protected]>Cc Lukasz Majewski <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151123/7c02a1ec/attachment.sig>
PATCH 1/1 dfu: fix possible memory leak in dfu_init_env_entities()
In reply to Przemyslaw MarczakHi Przemyslaw,
Quoted 23 lines
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 <[email protected]>Cc Lukasz Majewski <[email protected]>--- drivers/dfu/dfu.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/dfu/dfu.c +1
-1@@ -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)
drivers/dfu/dfu.c int dfu_init_env_entities(char *interface, char · line 76
Quoted 10 lines
drivers/dfu/dfu.c +1
-3error ("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.
Signature · 5 lines
Best regards, Lukasz Majewski Samsung R&D Institute Poland (SRPOL) | Linux Platform Group