]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
blkdev.cc::get_device_by_uuid: do not leak cache 5507/head
authorSamuel Just <sjust@redhat.com>
Wed, 22 Jul 2015 18:37:43 +0000 (11:37 -0700)
committerSamuel Just <sjust@redhat.com>
Wed, 22 Jul 2015 19:18:54 +0000 (12:18 -0700)
Fixes: #12436
Signed-off-by: Samuel Just <sjust@redhat.com>
src/common/blkdev.cc

index e6488aaa11025ccb74f0037545c36cd9479a3a6a..eb152f83af671c61064c280f074d4c03861db11b 100644 (file)
@@ -191,21 +191,29 @@ int get_device_by_uuid(uuid_d dev_uuid, const char* label, char* partition,
 
   if (blkid_get_cache(&cache, NULL) >= 0)
     dev = blkid_find_dev_with_tag(cache, label, (const char*)uuid_str);
+  else
+    rc = -EINVAL;
 
   if (dev) {
     temp_partition_ptr = blkid_dev_devname(dev);
     strncpy(partition, temp_partition_ptr, PATH_MAX);
     rc = get_block_device_base(partition, basename,
       sizeof(basename));
-    if (rc >= 0)
+    if (rc >= 0) {
       strncpy(device, basename, sizeof(basename));
-    else
-      return -ENODEV;
-
-    return 0;
+      rc = 0;
+    } else {
+      rc = -ENODEV;
+    }
+  } else {
+    rc = -EINVAL;
   }
 
-  return -EINVAL;
+  /* From what I can tell, blkid_put_cache cleans up dev, which
+   * appears to be a pointer into cache, as well */
+  if (cache)
+    blkid_put_cache(cache);
+  return rc;
 }
 #elif defined(__APPLE__)
 #include <sys/disk.h>