aboutsummaryrefslogtreecommitdiffstats
path: root/cmds-filesystem.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2016-03-15 10:25:00 +0100
committerDavid Sterba <dsterba@suse.com>2016-03-15 10:28:14 +0100
commit3299da86fe93c0ac4c3ef42739a525b1c2dd7af1 (patch)
tree3796f87b510790dd34276a2208ebf28909a9bf42 /cmds-filesystem.c
parent3bb71d27ac8f40554c0ba9748e411d2c2d4943d0 (diff)
downloadbtrfs-progs-3299da86fe93c0ac4c3ef42739a525b1c2dd7af1.tar.gz
btrfs-progs-3299da86fe93c0ac4c3ef42739a525b1c2dd7af1.tar.xz
btrfs-progs-3299da86fe93c0ac4c3ef42739a525b1c2dd7af1.zip
btrfs-progs: fix resource leak during device scanning
The dev info is leaked each time we find a known filesystem. Resolves-coverity-id: 1127098 Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-filesystem.c')
-rw-r--r--cmds-filesystem.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 45c16d2..38404d2 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -457,14 +457,14 @@ static int btrfs_scan_kernel(void *search, unsigned unit_mode)
memset(label, 0, sizeof(label));
while ((mnt = getmntent(f)) != NULL) {
+ free(dev_info_arg);
+ dev_info_arg = NULL;
if (strcmp(mnt->mnt_type, "btrfs"))
continue;
ret = get_fs_info(mnt->mnt_dir, &fs_info_arg,
&dev_info_arg);
- if (ret) {
- kfree(dev_info_arg);
+ if (ret)
goto out;
- }
/* skip all fs already shown as mounted fs */
if (is_seen_fsid(fs_info_arg.fsid))
@@ -476,14 +476,11 @@ static int btrfs_scan_kernel(void *search, unsigned unit_mode)
ret = get_label_unmounted(
(const char *)dev_info_arg->path, label);
- if (ret) {
- kfree(dev_info_arg);
+ if (ret)
goto out;
- }
+
if (search && !match_search_item_kernel(fs_info_arg.fsid,
mnt->mnt_dir, label, search)) {
- kfree(dev_info_arg);
- dev_info_arg = NULL;
continue;
}
@@ -497,11 +494,10 @@ static int btrfs_scan_kernel(void *search, unsigned unit_mode)
}
if (fd != -1)
close(fd);
- kfree(dev_info_arg);
- dev_info_arg = NULL;
}
out:
+ free(dev_info_arg);
endmntent(f);
return !found;
}