From: Jeff Liu <jeff.liu@oracle.com>
To: ocfs2-devel@oss.oracle.com
Subject: [Ocfs2-devel] [patch 1/4] ocfs2: fix a couple of memory leaks at o2hb_map_slot_data()
Date: Wed, 22 Aug 2012 17:38:09 +0800 [thread overview]
Message-ID: <5034A881.4010409@oracle.com> (raw)
This patch can fix a couple of potential memory leaks at o2hb_map_slot_data().
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
---
fs/ocfs2/cluster/heartbeat.c | 33 +++++++++++++++++++++++++--------
1 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index a4e855e..1b6ce53 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -1638,7 +1638,7 @@ static void o2hb_init_region_params(struct o2hb_region *reg)
static int o2hb_map_slot_data(struct o2hb_region *reg)
{
- int i, j;
+ int ret = 0, i, j;
unsigned int last_slot;
unsigned int spp = reg->hr_slots_per_page;
struct page *page;
@@ -1654,8 +1654,8 @@ static int o2hb_map_slot_data(struct o2hb_region *reg)
reg->hr_slots = kcalloc(reg->hr_blocks,
sizeof(struct o2hb_disk_slot), GFP_KERNEL);
if (reg->hr_slots == NULL) {
- mlog_errno(-ENOMEM);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto free;
}
for(i = 0; i < reg->hr_blocks; i++) {
@@ -1673,15 +1673,15 @@ static int o2hb_map_slot_data(struct o2hb_region *reg)
reg->hr_slot_data = kcalloc(reg->hr_num_pages, sizeof(struct page *),
GFP_KERNEL);
if (!reg->hr_slot_data) {
- mlog_errno(-ENOMEM);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto free;
}
for(i = 0; i < reg->hr_num_pages; i++) {
page = alloc_page(GFP_KERNEL);
if (!page) {
- mlog_errno(-ENOMEM);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto free;
}
reg->hr_slot_data[i] = page;
@@ -1701,7 +1701,24 @@ static int o2hb_map_slot_data(struct o2hb_region *reg)
}
}
- return 0;
+ return ret;
+
+free:
+ mlog_errno(ret);
+
+ kfree(reg->hr_tmp_block);
+ kfree(reg->hr_slots);
+
+ if (reg->hr_slot_data) {
+ for (i = 0; i < reg->hr_num_pages; i++) {
+ page = reg->hr_slot_data[i];
+ if (page)
+ __free_page(reg->hr_slot_data[i]);
+ }
+ kfree(reg->hr_slot_data);
+ }
+
+ return ret;
}
/* Read in all the slots available and populate the tracking
--
1.7.4.1
next reply other threads:[~2012-08-22 9:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-22 9:38 Jeff Liu [this message]
-- strict thread matches above, loose matches on Subject: below --
2013-05-27 11:32 [Ocfs2-devel] [patch 1/4] ocfs2: fix a couple of memory leaks at o2hb_map_slot_data() Joseph Qi
2013-05-27 11:56 ` Jeff Liu
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=5034A881.4010409@oracle.com \
--to=jeff.liu@oracle.com \
--cc=ocfs2-devel@oss.oracle.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