diff options
author | BangLang Huang <banglang.huang@foxmail.com> | 2017-02-24 10:16:17 +0800 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2017-12-13 16:23:39 +0100 |
commit | 9e84d333b19abdfe5effd276421217a64dd98078 (patch) | |
tree | 82637d00f95d4eb5308ded578cf95a7d0e891c28 /package/utils/nvram/src/nvram.c | |
parent | 3b6b892d675fdb724fb523fa8a14cf0e8068f959 (diff) | |
download | upstream-9e84d333b19abdfe5effd276421217a64dd98078.tar.gz upstream-9e84d333b19abdfe5effd276421217a64dd98078.tar.bz2 upstream-9e84d333b19abdfe5effd276421217a64dd98078.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>
(cherry picked from commit 1948d8e08c72106a01b359a30217cf92657cc79d)
Diffstat (limited to 'package/utils/nvram/src/nvram.c')
-rw-r--r-- | package/utils/nvram/src/nvram.c | 3 |
1 files changed, 3 insertions, 0 deletions
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; } |