libgfapi: fix memory leak on old volume files

Fix missing free of fs->oldvolfile. This patch uses standard
calloc/realloc to allocate memory for vol file. As by the time fs struct
is destroyed, the THIS->ctx is already gone, that causes invalid memory
access.

Change-Id: I72ae19c76eb16e61f077714f7e52405fee721997
fixes: bz#1607689
Signed-off-by: Zhang Huan <zhanghuan@open-fs.com>
This commit is contained in:
Zhang Huan 2018-07-23 15:27:41 +08:00 committed by Amar Tumballi
parent a6b5ec5cb5
commit 75300258c4
2 changed files with 5 additions and 2 deletions

View File

@ -549,9 +549,9 @@ glusterfs_oldvolfile_update (struct glfs *fs, char *volfile, ssize_t size)
fs->oldvollen = size;
if (!fs->oldvolfile) {
fs->oldvolfile = GF_CALLOC (1, size+1, glfs_mt_volfile_t);
fs->oldvolfile = CALLOC (1, size+1);
} else {
fs->oldvolfile = GF_REALLOC (fs->oldvolfile, size+1);
fs->oldvolfile = REALLOC (fs->oldvolfile, size+1);
}
if (!fs->oldvolfile) {

View File

@ -971,6 +971,9 @@ priv_glfs_free_from_ctx (struct glfs *fs)
PTHREAD_MUTEX_DESTROY (&fs->upcall_list_mutex, fs->pthread_flags,
GLFS_INIT_MUTEX_UPCALL);
if (fs->oldvolfile)
FREE (fs->oldvolfile);
FREE (fs->volname);
FREE (fs);