]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
fuse: use c++ allocations for group list 17204/head
authorJeff Layton <jlayton@redhat.com>
Wed, 23 Aug 2017 16:13:14 +0000 (12:13 -0400)
committerJeff Layton <jlayton@redhat.com>
Wed, 23 Aug 2017 16:13:14 +0000 (12:13 -0400)
Valgrind is unhappy about our turning on supplimentary group handling
with fuse by default. The problem is that we end up calling delete to
free the supplimentary gids list, but fuse uses malloc to allocate it.

Note that I was initially concerned that I needed to use malloc and
free there to handle the case of userland calling ceph_userperm_new,
but we leave freeing the pointer up to the caller in that case.

Convert fuse to use new/delete to allocate and free the group lists
instead.

Tracker: http://tracker.ceph.com/issues/21065
Signed-off-by: Jeff Layton <jlayton@redhat.com>
src/client/fuse_ll.cc

index cbb0bb0762e3b017f2b420eaa4efdc248fc5b414..d24ad5c3451a14a5211988510e313af7efd06589 100644 (file)
@@ -112,14 +112,15 @@ static int getgroups(fuse_req_t req, gid_t **sgids)
     return 0;
   }
 
-  *sgids = (gid_t*)malloc(c*sizeof(**sgids));
-  if (!*sgids) {
+  gid_t *gids = new (std::nothrow) gid_t[c];
+  if (!gids) {
     return -ENOMEM;
   }
-  c = fuse_req_getgroups(req, c, *sgids);
+  c = fuse_req_getgroups(req, c, gids);
   if (c < 0) {
-    free(*sgids);
-    return c;
+    delete gids;
+  } else {
+    *sgids = gids;
   }
   return c;
 #endif