From: Wang Sheng-Hui <shhuiw@gmail.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] btrfs-progs: avoid memory leak in find_and_setup_log_root
Date: Thu, 25 Oct 2012 10:59:20 +0800 [thread overview]
Message-ID: <5088AB08.9080902@gmail.com> (raw)
In find_and_setup_log_root, the malloced log_root would be leaked
if we have bytenr = 0, which would happen at our mkfs stage.
Move the memory allocation after the bytenr check, and add allocation
failure check.
Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
---
disk-io.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/disk-io.c b/disk-io.c
index 0395205..3a80284 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -456,11 +456,15 @@ static int find_and_setup_log_root(struct btrfs_root *tree_root,
{
u32 blocksize;
u64 blocknr = btrfs_super_log_root(disk_super);
- struct btrfs_root *log_root = malloc(sizeof(struct btrfs_root));
+ struct btrfs_root *log_root = NULL;
if (blocknr == 0)
return 0;
+ log_root = malloc(sizeof(struct btrfs_root));
+ if (!log_root)
+ return -ENOMEM;
+
blocksize = btrfs_level_size(tree_root,
btrfs_super_log_root_level(disk_super));
--
1.7.5.4
reply other threads:[~2012-10-25 2:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=5088AB08.9080902@gmail.com \
--to=shhuiw@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/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).