From 10c0b679056a70ac491c6e3d0cc4b7f931758a3d Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Wed, 22 Jul 2015 11:37:43 -0700 Subject: [PATCH] blkdev.cc::get_device_by_uuid: do not leak cache Fixes: #12436 Signed-off-by: Samuel Just --- src/common/blkdev.cc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/common/blkdev.cc b/src/common/blkdev.cc index e6488aaa110..eb152f83af6 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