summaryrefslogtreecommitdiff
path: root/mkfs.c
diff options
context:
space:
mode:
authorSergei Trofimovich <slyfox@gentoo.org>2011-06-04 11:19:23 +0300
committerChris Mason <chris.mason@oracle.com>2011-10-25 09:18:58 -0400
commitd69c30808c07f144403f508885f6f1d569f888bb (patch)
tree05ed27d26faf40c6ab58571e0fe7b4cf3e0b886c /mkfs.c
parente06947319cf4558c26d9457a934eb992b34d93e4 (diff)
mkfs.btrfs: fix memory leak caused by 'scandir()' calls
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org> Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
Diffstat (limited to 'mkfs.c')
-rw-r--r--mkfs.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/mkfs.c b/mkfs.c
index 5701c0ab..b93b874e 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -468,6 +468,18 @@ static int directory_select(const struct direct *entry)
return 1;
}
+static void free_namelist(struct direct **files, int count)
+{
+ int i;
+
+ if (count < 0)
+ return;
+
+ for (i = 0; i < count; ++i)
+ free(files[i]);
+ free(files);
+}
+
static u64 calculate_dir_inode_size(char *dirname)
{
int count, i;
@@ -481,6 +493,8 @@ static u64 calculate_dir_inode_size(char *dirname)
dir_inode_size += strlen(cur_file->d_name);
}
+ free_namelist(files, count);
+
dir_inode_size *= 2;
return dir_inode_size;
}
@@ -971,6 +985,7 @@ static int traverse_directory(struct btrfs_trans_handle *trans,
}
}
+ free_namelist(files, count);
free(parent_dir_entry->path);
free(parent_dir_entry);
@@ -980,6 +995,7 @@ static int traverse_directory(struct btrfs_trans_handle *trans,
return 0;
fail:
+ free_namelist(files, count);
free(parent_dir_entry->path);
free(parent_dir_entry);
return -1;