From ba2302346433af7150193025aa8a446fa3238445 Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Wed, 12 Nov 2014 09:18:55 +0100 Subject: [PATCH] coverity: fix resource leaks LVM2.2.02.112/tools/toollib.c:1991: leaked_storage: Variable "iter" going out of scope leaks the storage it points to. LVM2.2.02.112/lib/filters/filter-usable.c:89: leaked_storage: Variable "f" going out of scope leaks the storage it points to. LVM2.2.02.112/lib/activate/dev_manager.c:1874: leaked_handle: Handle variable "fd" going out of scope leaks the handle. --- lib/activate/dev_manager.c | 2 ++ lib/filters/filter-usable.c | 1 + tools/toollib.c | 8 +++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c index a39238739..efaaa6507 100644 --- a/lib/activate/dev_manager.c +++ b/lib/activate/dev_manager.c @@ -1870,6 +1870,8 @@ static int _pool_callback(struct dm_tree_node *node, } /* let's assume there is no problem to read 64 bytes */ if (read(fd, buf, sizeof(buf)) < sizeof(buf)) { + if (close(fd)) + log_sys_error("close", argv[args]); log_sys_error("read", argv[args]); return 0; } diff --git a/lib/filters/filter-usable.c b/lib/filters/filter-usable.c index a6932b05e..f34a325fc 100644 --- a/lib/filters/filter-usable.c +++ b/lib/filters/filter-usable.c @@ -86,6 +86,7 @@ struct dev_filter *usable_filter_create(struct dev_types *dt __attribute__((unus f->use_count = 0; if (!(f->private = dm_zalloc(sizeof(filter_mode_t)))) { log_error("Usable device filter mode allocation failed"); + dm_free(f); return NULL; } *((filter_mode_t *) f->private) = mode; diff --git a/tools/toollib.c b/tools/toollib.c index 596dba543..e47213d63 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -1977,6 +1977,7 @@ static int _get_all_devices(struct cmd_context *cmd, struct dm_list *all_devices struct dev_iter *iter; struct device *dev; struct device_list *devl; + int r = ECMD_FAILED; lvmcache_seed_infos_from_lvmetad(cmd); @@ -1988,16 +1989,17 @@ static int _get_all_devices(struct cmd_context *cmd, struct dm_list *all_devices while ((dev = dev_iter_get(iter))) { if (!(devl = dm_pool_alloc(cmd->mem, sizeof(*devl)))) { log_error("device_list alloc failed"); - return ECMD_FAILED; + goto out; } devl->dev = dev; dm_list_add(all_devices, &devl->list); } + r = ECMD_PROCESSED; +out: dev_iter_destroy(iter); - - return ECMD_PROCESSED; + return r; } static int _device_list_remove(struct dm_list *all_devices, struct device *dev)