[source] packages: nvram: fix memory leak in _nvram_free

LEDE Commits lede-commits at lists.infradead.org
Thu Dec 14 09:45:38 PST 2017


jow pushed a commit to source.git, branch lede-17.01:
https://git.lede-project.org/06258144266a5adb44d2ef072c2a7c051584a24d

commit 06258144266a5adb44d2ef072c2a7c051584a24d
Author: Zhai Zhaoxuan <zhaizhaoxuan at xiaomi.com>
AuthorDate: Tue Jul 11 18:12:00 2017 +0800

    packages: nvram: fix memory leak in _nvram_free
    
    The value of nvram_tuple_t is allocated in _nvram_realloc,
    but it is not freed in _nvram_free.
    
    Signed-off-by: Zhai Zhaoxuan <zhaizhaoxuan at xiaomi.com>
    (cherry picked from commit c382237ac33a787043b22abc42f0c5a80278baae)
---
 package/utils/nvram/src/nvram.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/package/utils/nvram/src/nvram.c b/package/utils/nvram/src/nvram.c
index ca89392..d5e12ee 100644
--- a/package/utils/nvram/src/nvram.c
+++ b/package/utils/nvram/src/nvram.c
@@ -47,6 +47,8 @@ static void _nvram_free(nvram_handle_t *h)
 	for (i = 0; i < NVRAM_ARRAYSIZE(h->nvram_hash); i++) {
 		for (t = h->nvram_hash[i]; t; t = next) {
 			next = t->next;
+			if (t->value)
+				free(t->value);
 			free(t);
 		}
 		h->nvram_hash[i] = NULL;
@@ -55,6 +57,8 @@ static void _nvram_free(nvram_handle_t *h)
 	/* Free dead table */
 	for (t = h->nvram_dead; t; t = next) {
 		next = t->next;
+		if (t->value)
+			free(t->value);
 		free(t);
 	}
 



More information about the lede-commits mailing list