libbtrfsutil: fix memory leak in deleted_subvolumes()
authorOmar Sandoval <osandov@fb.com>
Thu, 29 Mar 2018 07:53:54 +0000 (00:53 -0700)
committerDavid Sterba <dsterba@suse.com>
Fri, 30 Mar 2018 20:53:57 +0000 (22:53 +0200)
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>
libbtrfsutil/subvolume.c

index d6c0ced..867b3e1 100644 (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;