summaryrefslogtreecommitdiff
path: root/qgroup.c
diff options
context:
space:
mode:
authorByongho Lee <bhlee.kernel@gmail.com>2015-08-21 17:51:52 +0900
committerDavid Sterba <dsterba@suse.com>2015-08-31 19:25:12 +0200
commitae60507e59a1cad43303a0f9e1b72ef4e5bb1e72 (patch)
tree180a89c224d665244ca3c9b1da680203b2c62d5d /qgroup.c
parentd7748770a78a4a44f39f4f0e629885a255d24d90 (diff)
btrfs-progs: fix memory leaks in error path
This patch includes below fixes in error path: 1. fix memory leaks if realloc() fails 2. add missing call free_history() before return error in scrub_read_file() Signed-off-by: Byongho Lee <bhlee.kernel@gmail.com> Reviewed-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'qgroup.c')
-rw-r--r--qgroup.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/qgroup.c b/qgroup.c
index dc04b033..327abd64 100644
--- a/qgroup.c
+++ b/qgroup.c
@@ -465,12 +465,16 @@ int btrfs_qgroup_setup_comparer(struct btrfs_qgroup_comparer_set **comp_set,
BUG_ON(set->ncomps > set->total);
if (set->ncomps == set->total) {
+ void *tmp;
+
size = set->total + BTRFS_QGROUP_NCOMPS_INCREASE;
size = sizeof(*set) +
size * sizeof(struct btrfs_qgroup_comparer);
+ tmp = set;
set = realloc(set, size);
if (!set) {
fprintf(stderr, "memory allocation failed\n");
+ free(tmp);
exit(1);
}
@@ -836,12 +840,16 @@ int btrfs_qgroup_setup_filter(struct btrfs_qgroup_filter_set **filter_set,
BUG_ON(set->nfilters > set->total);
if (set->nfilters == set->total) {
+ void *tmp;
+
size = set->total + BTRFS_QGROUP_NFILTERS_INCREASE;
size = sizeof(*set) + size * sizeof(struct btrfs_qgroup_filter);
+ tmp = set;
set = realloc(set, size);
if (!set) {
fprintf(stderr, "memory allocation failed\n");
+ free(tmp);
exit(1);
}
memset(&set->filters[set->total], 0,