From 75300258c42aeb29350ac55beb3360ca208454b5 Mon Sep 17 00:00:00 2001 From: Zhang Huan Date: Mon, 23 Jul 2018 15:27:41 +0800 Subject: 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 --- api/src/glfs-mgmt.c | 4 ++-- api/src/glfs.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'api') diff --git a/api/src/glfs-mgmt.c b/api/src/glfs-mgmt.c index 911a7330512..994f43c82f2 100644 --- a/api/src/glfs-mgmt.c +++ b/api/src/glfs-mgmt.c @@ -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) { diff --git a/api/src/glfs.c b/api/src/glfs.c index 6f7b6cde56d..a249534ffef 100644 --- a/api/src/glfs.c +++ b/api/src/glfs.c @@ -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); -- cgit