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>
This commit is contained in:
committed by
Alexander Couzens
parent
e622b30730
commit
1948d8e08c
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user