]> 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)
committerYan, Zheng <zyan@redhat.com>
Thu, 3 Mar 2016 12:30:07 +0000 (20:30 +0800)
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>
Signed-off-by: Yan, Zheng <zyan@redhat.com>
(cherry picked from commit 4f98dab99c35663de89a06e2dfdbd874f56aed41)

src/client/Client.cc

index 9862f9b8d14239e8a2c9ce8adfb24a446e48af51..43131f8d257e1cbb8dffec27ddea4115b22e6511 100644 (file)
@@ -4419,11 +4419,13 @@ int Client::check_permissions(Inode *in, int flags, int uid, int gid)
     while (1) {
       if (getgrouplist(pw->pw_name, gid, sgids, &sgid_count) == -1) {
        // 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