From 4f98dab99c35663de89a06e2dfdbd874f56aed41 Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Wed, 12 Aug 2015 18:38:38 +0200 Subject: [PATCH] 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 --- src/client/Client.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 -- 2.47.3