From: Danny Al-Gaaf Date: Wed, 12 Aug 2015 16:38:38 +0000 (+0200) Subject: client/Client.cc: fix realloc memory leak X-Git-Tag: v9.1.0~128^2~19 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4f98dab99c35663de89a06e2dfdbd874f56aed41;p=ceph.git client/Client.cc: fix realloc memory leak Fix handling of realloc. If realloc() fails it returns NULL, assigning the return value of realloc() directly to the pointer without checking for the result will lead to a memory leak. Signed-off-by: Danny Al-Gaaf --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 638ceecb5855..20e946d8e87c 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -4597,11 +4597,13 @@ int Client::check_permissions(Inode *in, int flags, int uid, int gid) if (getgrouplist(pw->pw_name, gid, sgids, &sgid_count) == -1) { #endif // we need to resize the group list and try again - sgids = (gid_t*)realloc(sgids, sgid_count * sizeof(gid_t)); - if (sgids == NULL) { + void *_realloc = NULL; + if ((_realloc = realloc(sgids, sgid_count * sizeof(gid_t))) == NULL) { ldout(cct, 3) << "allocating group memory failed" << dendl; + free(sgids); return -EACCES; } + sgids = (gid_t*)_realloc; continue; } // list was successfully retrieved