From 1948d8e08c72106a01b359a30217cf92657cc79d Mon Sep 17 00:00:00 2001 From: BangLang Huang Date: Fri, 24 Feb 2017 10:16:17 +0800 Subject: nvram: fix memory leak Fix memory leak on nvram_open() and nvram_open_rdonly(). For nvram_open(), the 'fd' should be closed on error, and mmap_area should be unmap when nvram magic can not be found. For nvram_open_rdonly(), the 'file' variable should free before return. Once nvram_find_mtd() return successfully, it will allocate memory to save mtd device string. Signed-off-by: BangLang Huang --- package/utils/nvram/src/cli.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'package/utils/nvram/src/cli.c') diff --git a/package/utils/nvram/src/cli.c b/package/utils/nvram/src/cli.c index 488d641cfc..4f9c77804d 100644 --- a/package/utils/nvram/src/cli.c +++ b/package/utils/nvram/src/cli.c @@ -27,13 +27,17 @@ static nvram_handle_t * nvram_open_rdonly(void) { - const char *file = nvram_find_staging(); + char *file = nvram_find_staging(); if( file == NULL ) file = nvram_find_mtd(); - if( file != NULL ) - return nvram_open(file, NVRAM_RO); + if( file != NULL ) { + nvram_handle_t *h = nvram_open(file, NVRAM_RO); + if( strcmp(file, NVRAM_STAGING) ) + free(file); + return h; + } return NULL; } -- cgit v1.2.3