]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client/Client.cc: fix realloc memory leak
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Wed, 12 Aug 2015 16:38:38 +0000 (18:38 +0200)
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>
Wed, 9 Sep 2015 13:36:44 +0000 (15:36 +0200)
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 <danny.al-gaaf@bisect.de>
src/client/Client.cc

index 638ceecb58558a4a5b68e668c98321dafe457d4e..20e946d8e87c5295889d5d2eb56cc5e168bb9e29 100644 (file)
@@ -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