Skip to contentSkip to conversation

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

PATCH New Rakesh Pandit 1 participant 1 message Apr 19, 2014 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs-progs: fi-disk_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.

---
 cmds-fi-disk_usage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmds-fi-disk_usage.c +1 -1
index 2bd591d..cd71c8d 100644
@@ -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;
 			}
 
Signature · 1 line
1.8.5.3