aboutsummaryrefslogtreecommitdiffstats
path: root/package/utils/nvram
diff options
context:
space:
mode:
authorBangLang Huang <banglang.huang@foxmail.com>2017-02-24 10:16:17 +0800
committerAlexander Couzens <lynxis@fe80.eu>2017-08-22 14:31:32 +0200
commit1948d8e08c72106a01b359a30217cf92657cc79d (patch)
treebbc4501f33905e3baf69e8e908ae5ca68627939b /package/utils/nvram
parente622b307307856d284addc52e8172fdf66252d96 (diff)
downloadupstream-1948d8e08c72106a01b359a30217cf92657cc79d.tar.gz
upstream-1948d8e08c72106a01b359a30217cf92657cc79d.tar.bz2
upstream-1948d8e08c72106a01b359a30217cf92657cc79d.zip
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 <banglang.huang@foxmail.com>
Diffstat (limited to 'package/utils/nvram')
-rw-r--r--package/utils/nvram/src/cli.c10
-rw-r--r--package/utils/nvram/src/nvram.c3
2 files changed, 10 insertions, 3 deletions
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;
}
diff --git a/package/utils/nvram/src/nvram.c b/package/utils/nvram/src/nvram.c
index 0e4294391a..ca89392107 100644
--- a/package/utils/nvram/src/nvram.c
+++ b/package/utils/nvram/src/nvram.c
@@ -380,7 +380,9 @@ nvram_handle_t * nvram_open(const char *file, int rdonly)
if( offset < 0 )
{
+ munmap(mmap_area, nvram_part_size);
free(mtd);
+ close(fd);
return NULL;
}
else if( (h = malloc(sizeof(nvram_handle_t))) != NULL )
@@ -410,6 +412,7 @@ nvram_handle_t * nvram_open(const char *file, int rdonly)
}
free(mtd);
+ close(fd);
return NULL;
}