U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <l.majewski@majess.pl>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/2] FIX: env: import: hashtable: Free memory allocated before exiting from himport_r()
Date: Mon, 14 Sep 2015 00:57:04 +0200	[thread overview]
Message-ID: <1442185024-14645-2-git-send-email-l.majewski@majess.pl> (raw)
In-Reply-To: <1442185024-14645-1-git-send-email-l.majewski@majess.pl>

Without this patch memory is not released on early exit.

Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>
---
 lib/hashtable.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/hashtable.c b/lib/hashtable.c
index 7df424a..02b4105 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -842,8 +842,10 @@ int himport_r(struct hsearch_data *htab,
 		}
 	}
 
-	if(!size)
+	if (!size) {
+		free(data);
 		return 1;		/* everything OK */
+	}
 	if(crlf_is_lf) {
 		/* Remove Carriage Returns in front of Line Feeds */
 		unsigned ignored_crs = 0;
@@ -907,6 +909,7 @@ int himport_r(struct hsearch_data *htab,
 		if (*name == 0) {
 			debug("INSERT: unable to use an empty key\n");
 			__set_errno(EINVAL);
+			free(data);
 			return 0;
 		}
 
-- 
2.1.4

  reply	other threads:[~2015-09-13 22:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-13 22:57 [U-Boot] [PATCH 1/2] FIX: env: import: hashtable: Prevent buffer overrun when importing environment from file Lukasz Majewski
2015-09-13 22:57 ` Lukasz Majewski [this message]
2015-09-15 21:34   ` [U-Boot] [U-Boot, 2/2] FIX: env: import: hashtable: Free memory allocated before exiting from himport_r() Tom Rini
2015-09-15 21:34 ` [U-Boot] [U-Boot, 1/2] FIX: env: import: hashtable: Prevent buffer overrun when importing environment from file Tom Rini

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=1442185024-14645-2-git-send-email-l.majewski@majess.pl \
    --to=l.majewski@majess.pl \
    --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