libbtrfsutil: fix memory leak in deleted_subvolumes()

If we fail to reallocate the ID array, we still need to free it.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
master
Omar Sandoval 2018-03-29 00:53:54 -07:00 committed by David Sterba
parent c41c5b1562
commit f5dd778f52
1 changed files with 4 additions and 2 deletions

View File

@ -1353,8 +1353,10 @@ PUBLIC enum btrfs_util_error btrfs_util_deleted_subvolumes_fd(int fd,
new_capacity = capacity ? capacity * 2 : 1;
new_ids = reallocarray(*ids, new_capacity,
sizeof(**ids));
if (!new_ids)
return BTRFS_UTIL_ERROR_NO_MEMORY;
if (!new_ids) {
err = BTRFS_UTIL_ERROR_NO_MEMORY;
goto out;
}
*ids = new_ids;
capacity = new_capacity;