From: Prasanth K S R <kosigiprasanth@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Prasanth K S R <prasanth.ksr@dell.com>, dsterba@suse.com
Subject: [PATCH 3/3] Btrfs-progs: subvol_uuid_search: Return error code on memory allocation failure
Date: Sat, 10 Dec 2016 19:17:44 +0530 [thread overview]
Message-ID: <20161210134744.10825-3-kosigiprasanth@gmail.com> (raw)
In-Reply-To: <20161210134744.10825-1-kosigiprasanth@gmail.com>
From: Prasanth K S R <prasanth.ksr@dell.com>
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>
---
send-utils.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/send-utils.c b/send-utils.c
index 252ca6d..95445b5 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);
}
--
2.10.2
next prev parent reply other threads:[~2016-12-10 13:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-10 13:47 [PATCH 1/3] Btrfs-progs: subvol_uuid_search: Return error on memory allocation failure Prasanth K S R
2016-12-10 13:47 ` [PATCH 2/3] Btrfs-progs: subvol_uuid_search: Return error encoded pointer Prasanth K S R
2016-12-10 13:47 ` Prasanth K S R [this message]
2016-12-12 16:35 ` [PATCH 1/3] Btrfs-progs: subvol_uuid_search: Return error on memory allocation failure David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161210134744.10825-3-kosigiprasanth@gmail.com \
--to=kosigiprasanth@gmail.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=prasanth.ksr@dell.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).