From: Samuel Just Date: Wed, 22 Jul 2015 18:37:43 +0000 (-0700) Subject: blkdev.cc::get_device_by_uuid: do not leak cache X-Git-Tag: v9.1.0~423^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=10c0b679056a70ac491c6e3d0cc4b7f931758a3d;p=ceph.git blkdev.cc::get_device_by_uuid: do not leak cache Fixes: #12436 Signed-off-by: Samuel Just --- diff --git a/src/common/blkdev.cc b/src/common/blkdev.cc index e6488aaa1102..eb152f83af67 100644 --- a/src/common/blkdev.cc +++ b/src/common/blkdev.cc @@ -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