summaryrefslogtreecommitdiffstats
path: root/Assemble.c
diff options
context:
space:
mode:
authorGuoqing Jiang <gqjiang@suse.com>2018-06-11 11:03:44 +0200
committerJes Sorensen <jsorensen@fb.com>2018-06-11 12:35:41 +0200
commit898bd1ecefe6c72102f398680dcfef80e4de21c1 (patch)
tree070d1e320818fe345503a00356fbcf191e80247a /Assemble.c
parentimsm: correct num_data_stripes in metadata map for migration (diff)
downloadmdadm-898bd1ecefe6c72102f398680dcfef80e4de21c1.tar.xz
mdadm-898bd1ecefe6c72102f398680dcfef80e4de21c1.zip
Free map to avoid resource leak issues
1. There are some places which didn't free map as discovered by coverity. CID 289661 (#1 of 1): Resource leak (RESOURCE_LEAK)12. leaked_storage: Variable mapl going out of scope leaks the storage it points to. CID 289619 (#3 of 3): Resource leak (RESOURCE_LEAK)63. leaked_storage: Variable map going out of scope leaks the storage it points to. CID 289618 (#1 of 1): Resource leak (RESOURCE_LEAK)26. leaked_storage: Variable map going out of scope leaks the storage it points to. CID 289607 (#1 of 1): Resource leak (RESOURCE_LEAK)41. leaked_storage: Variable map going out of scope leaks the storage it points to. 2. If we call map_by_* inside a loop, then map_free should be called in the same loop, and it is better to set map to NULL after free. 3. And map_unlock is always called with map_lock, if we don't call map_remove before map_unlock, then the memory (allocated by map_lock -> map_read -> map_add -> xmalloc) could be leaked. So we need to free it in map_unlock as well. Signed-off-by: Guoqing Jiang <gqjiang@suse.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
Diffstat (limited to 'Assemble.c')
-rw-r--r--Assemble.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/Assemble.c b/Assemble.c
index 32e6f6ff..5a907c14 100644
--- a/Assemble.c
+++ b/Assemble.c
@@ -1851,8 +1851,8 @@ try_again:
if (rv == 1 && !pre_exist)
ioctl(mdfd, STOP_ARRAY, NULL);
free(devices);
- map_unlock(&map);
out:
+ map_unlock(&map);
if (rv == 0) {
wait_for(chosen_name, mdfd);
close(mdfd);