diff mbox

[U-Boot,2/2] FIX: env: import: hashtable: Free memory allocated before exiting from himport_r()

Message ID 1442185024-14645-2-git-send-email-l.majewski@majess.pl
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Lukasz Majewski Sept. 13, 2015, 10:57 p.m. UTC
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(-)

Comments

Tom Rini Sept. 15, 2015, 9:34 p.m. UTC | #1
On Mon, Sep 14, 2015 at 12:57:04AM +0200, Lukasz Majewski wrote:

> Without this patch memory is not released on early exit.
> 
> Signed-off-by: Lukasz Majewski <l.majewski@majess.pl>

Applied to u-boot/master, thanks!
diff mbox

Patch

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;
 		}