Btrfs-progs: fi usage: free memory if realloc fails

Lets not assign *info_ptr to 0 before calling free on it and lose
track of already allocated memory if realloc fails in
add_info_to_list. Lets call free first.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
Rakesh Pandit 2014-04-19 14:12:03 +03:00 committed by David Sterba
parent 7c7fd19b8d
commit 0c1f1b2ae8
1 changed files with 1 additions and 1 deletions

View File

@ -104,6 +104,7 @@ static int add_info_to_list(struct chunk_info **info_ptr,
struct chunk_info *res = realloc(*info_ptr, size);
if (!res) {
free(*info_ptr);
fprintf(stderr, "ERROR: not enough memory\n");
return -1;
}
@ -224,7 +225,6 @@ static int load_chunk_info(int fd,
if (add_info_to_list(info_ptr, info_count, item)) {
*info_ptr = 0;
free(*info_ptr);
return -100;
}