All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/1] tools/env: avoid memory leak in fw_setenv
@ 2017-04-15 10:56 Heinrich at lists.denx.de
  2017-04-15 11:05 ` [U-Boot] [PATCH v2 " Heinrich Schuchardt
  0 siblings, 1 reply; 5+ messages in thread
From: Heinrich at lists.denx.de @ 2017-04-15 10:56 UTC (permalink / raw)
  To: u-boot

From: Heinrich Schuchardt <xypron.glpk@gmx.de>

If realloc fails we should release the old buffer.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 tools/env/fw_env.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 862a0b1a02..31c18d73bc 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -469,6 +469,7 @@ int fw_setenv(int argc, char *argv[], struct env_opts *opts)
 	int i;
 	size_t len;
 	char *name, **valv;
+	char *oldval;
 	char *value = NULL;
 	int valc;
 
@@ -500,11 +501,13 @@ int fw_setenv(int argc, char *argv[], struct env_opts *opts)
 
 		if (value)
 			value[len - 1] = ' ';
+		oldval = value;
 		value = realloc(value, len + val_len + 1);
 		if (!value) {
 			fprintf(stderr,
 				"Cannot malloc %zu bytes: %s\n",
 				len, strerror(errno));
+			free(oldval);
 			return -1;
 		}
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v2 1/1] tools/env: avoid memory leak in fw_setenv
  2017-04-15 10:56 [U-Boot] [PATCH 1/1] tools/env: avoid memory leak in fw_setenv Heinrich at lists.denx.de
@ 2017-04-15 11:05 ` Heinrich Schuchardt
  2017-04-15 16:11   ` Tom Rini
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Heinrich Schuchardt @ 2017-04-15 11:05 UTC (permalink / raw)
  To: u-boot

If realloc fails we should release the old buffer.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
v2:
  Initial mail was garbled.
---
 tools/env/fw_env.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 862a0b1a02..31c18d73bc 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -469,6 +469,7 @@ int fw_setenv(int argc, char *argv[], struct env_opts *opts)
 	int i;
 	size_t len;
 	char *name, **valv;
+	char *oldval;
 	char *value = NULL;
 	int valc;
 
@@ -500,11 +501,13 @@ int fw_setenv(int argc, char *argv[], struct env_opts *opts)
 
 		if (value)
 			value[len - 1] = ' ';
+		oldval = value;
 		value = realloc(value, len + val_len + 1);
 		if (!value) {
 			fprintf(stderr,
 				"Cannot malloc %zu bytes: %s\n",
 				len, strerror(errno));
+			free(oldval);
 			return -1;
 		}
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v2 1/1] tools/env: avoid memory leak in fw_setenv
  2017-04-15 11:05 ` [U-Boot] [PATCH v2 " Heinrich Schuchardt
@ 2017-04-15 16:11   ` Tom Rini
  2017-04-16 19:34   ` Simon Glass
  2017-04-19 13:03   ` [U-Boot] [U-Boot, v2, " Tom Rini
  2 siblings, 0 replies; 5+ messages in thread
From: Tom Rini @ 2017-04-15 16:11 UTC (permalink / raw)
  To: u-boot

On Sat, Apr 15, 2017 at 01:05:40PM +0200, Heinrich Schuchardt wrote:

> If realloc fails we should release the old buffer.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170415/027f33d5/attachment.sig>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v2 1/1] tools/env: avoid memory leak in fw_setenv
  2017-04-15 11:05 ` [U-Boot] [PATCH v2 " Heinrich Schuchardt
  2017-04-15 16:11   ` Tom Rini
@ 2017-04-16 19:34   ` Simon Glass
  2017-04-19 13:03   ` [U-Boot] [U-Boot, v2, " Tom Rini
  2 siblings, 0 replies; 5+ messages in thread
From: Simon Glass @ 2017-04-16 19:34 UTC (permalink / raw)
  To: u-boot

On 15 April 2017 at 05:05, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> If realloc fails we should release the old buffer.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> v2:
>   Initial mail was garbled.
> ---
>  tools/env/fw_env.c | 3 +++
>  1 file changed, 3 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [U-Boot, v2, 1/1] tools/env: avoid memory leak in fw_setenv
  2017-04-15 11:05 ` [U-Boot] [PATCH v2 " Heinrich Schuchardt
  2017-04-15 16:11   ` Tom Rini
  2017-04-16 19:34   ` Simon Glass
@ 2017-04-19 13:03   ` Tom Rini
  2 siblings, 0 replies; 5+ messages in thread
From: Tom Rini @ 2017-04-19 13:03 UTC (permalink / raw)
  To: u-boot

On Sat, Apr 15, 2017 at 01:05:40PM +0200, xypron.glpk at gmx.de wrote:

> If realloc fails we should release the old buffer.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Reviewed-by: Tom Rini <trini@konsulko.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170419/b8db7fa1/attachment.sig>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-04-19 13:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-15 10:56 [U-Boot] [PATCH 1/1] tools/env: avoid memory leak in fw_setenv Heinrich at lists.denx.de
2017-04-15 11:05 ` [U-Boot] [PATCH v2 " Heinrich Schuchardt
2017-04-15 16:11   ` Tom Rini
2017-04-16 19:34   ` Simon Glass
2017-04-19 13:03   ` [U-Boot] [U-Boot, v2, " Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.