btrfs-progs: handle memory allocation failures in traverse_directory

Signed-off-by: David Sterba <dsterba@suse.com>
master
David Sterba 2015-11-06 18:03:24 +01:00
parent 6046bfd5e3
commit 89b40ab5bb
1 changed files with 6 additions and 0 deletions

6
mkfs.c
View File

@ -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);