summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrasanth K S R <prasanth.ksr@dell.com>2016-12-10 19:17:44 +0530
committerDavid Sterba <dsterba@suse.com>2016-12-14 15:06:36 +0100
commitee518036d2cdf58d562b9448e3c062d5653c0d34 (patch)
treec7d4084b860e5959a65ae7c4583c6de16af760e6
parenta2f7af94abe4a3491ca1280a2ae1d63edc0d62ab (diff)
btrfs-progs: subvol_uuid_search: return error code on memory allocation failure
On failure of memory allocation for a 'struct subvol_info', we would end up dereferencing a NULL pointer. This commit fixes the issue by returning an error encoded pointer. Signed-off-by: Prasanth K S R <prasanth.ksr@dell.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--send-utils.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/send-utils.c b/send-utils.c
index 252ca6df..95445b58 100644
--- a/send-utils.c
+++ b/send-utils.c
@@ -474,6 +474,10 @@ struct subvol_info *subvol_uuid_search(struct subvol_uuid_search *s,
goto out;
info = calloc(1, sizeof(*info));
+ if (!info) {
+ ret = -ENOMEM;
+ goto out;
+ }
info->root_id = root_id;
memcpy(info->uuid, root_item.uuid, BTRFS_UUID_SIZE);
memcpy(info->received_uuid, root_item.received_uuid, BTRFS_UUID_SIZE);
@@ -495,9 +499,11 @@ struct subvol_info *subvol_uuid_search(struct subvol_uuid_search *s,
}
out:
- if (ret && info) {
- free(info->path);
- free(info);
+ if (ret) {
+ if (info) {
+ free(info->path);
+ free(info);
+ }
return ERR_PTR(ret);
}