summaryrefslogtreecommitdiff
path: root/mkfs.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2015-11-06 18:03:24 +0100
committerDavid Sterba <dsterba@suse.com>2015-11-13 18:24:34 +0100
commit89b40ab5bbd8f2aff8c0a595a4d25faade0016d9 (patch)
treea03576f3cb43b326226efc7136959bc692bba99f /mkfs.c
parent6046bfd5e34054f61c682ec7e425e907a8f1e051 (diff)
btrfs-progs: handle memory allocation failures in traverse_directory
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'mkfs.c')
-rw-r--r--mkfs.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/mkfs.c b/mkfs.c
index 7316cb1c..c09cbd31 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -786,6 +786,8 @@ static int traverse_directory(struct btrfs_trans_handle *trans,
/* Add list for source directory */
dir_entry = malloc(sizeof(struct directory_name_entry));
+ if (!dir_entry)
+ return -ENOMEM;
dir_entry->dir_name = dir_name;
dir_entry->path = realpath(dir_name, real_path);
if (!dir_entry->path) {
@@ -887,6 +889,10 @@ static int traverse_directory(struct btrfs_trans_handle *trans,
if (S_ISDIR(st.st_mode)) {
dir_entry = malloc(sizeof(struct directory_name_entry));
+ if (!dir_entry) {
+ ret = -ENOMEM;
+ goto fail;
+ }
dir_entry->dir_name = cur_file->d_name;
dir_entry->path = make_path(parent_dir_entry->path,
cur_file->d_name);