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@xiaomi.com>
This commit is contained in:
Zhai Zhaoxuan 2017-07-11 18:12:00 +08:00 committed by John Crispin
parent 2dca7177e7
commit c382237ac3

View file

@ -47,6 +47,8 @@ static void _nvram_free(nvram_handle_t *h)
for (i = 0; i < NVRAM_ARRAYSIZE(h->nvram_hash); i++) { for (i = 0; i < NVRAM_ARRAYSIZE(h->nvram_hash); i++) {
for (t = h->nvram_hash[i]; t; t = next) { for (t = h->nvram_hash[i]; t; t = next) {
next = t->next; next = t->next;
if (t->value)
free(t->value);
free(t); free(t);
} }
h->nvram_hash[i] = NULL; h->nvram_hash[i] = NULL;
@ -55,6 +57,8 @@ static void _nvram_free(nvram_handle_t *h)
/* Free dead table */ /* Free dead table */
for (t = h->nvram_dead; t; t = next) { for (t = h->nvram_dead; t; t = next) {
next = t->next; next = t->next;
if (t->value)
free(t->value);
free(t); free(t);
} }