From: Artem Bityutskiy <dedekind1@gmail.com>
To: Sidney Amani <seed95@gmail.com>
Cc: Ben Gardiner <bengardiner@nanometrics.ca>,
MTD Maling List <linux-mtd@lists.infradead.org>
Subject: [PATCH 1/2] UBIFS: make ubifs_lpt_init clean-up in case of failure
Date: Fri, 18 May 2012 14:32:36 +0300 [thread overview]
Message-ID: <1337340757-26127-1-git-send-email-dedekind1@gmail.com> (raw)
In-Reply-To: <1337245412-22222-1-git-send-email-seed95@gmail.com>
From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Most functions in UBIFS follow the following designn pattern: if the function
allocates multiple resources, and failss at some point, it frees what it has
allocated and returns an error. So the caller can rely on the fact that the
callee has cleaned up everything after own failure.
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
---
fs/ubifs/lpt.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c
index 2054e81..b4280c4 100644
--- a/fs/ubifs/lpt.c
+++ b/fs/ubifs/lpt.c
@@ -1740,16 +1740,20 @@ int ubifs_lpt_init(struct ubifs_info *c, int rd, int wr)
if (rd) {
err = lpt_init_rd(c);
if (err)
- return err;
+ goto out_err;
}
if (wr) {
err = lpt_init_wr(c);
if (err)
- return err;
+ goto out_err;
}
return 0;
+
+out_err:
+ ubifs_lpt_free(c, 0);
+ return err;
}
/**
--
1.7.10
next prev parent reply other threads:[~2012-05-18 11:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-17 9:03 [PATCH] UBIFS: fix memory leak on error path Sidney Amani
2012-05-18 11:32 ` Artem Bityutskiy [this message]
2012-05-18 11:32 ` [PATCH 2/2] " Artem Bityutskiy
2012-05-20 5:49 ` [PATCH 1/2] UBIFS: make ubifs_lpt_init clean-up in case of failure Sidney Amani
2012-05-18 11:38 ` [PATCH] UBIFS: fix memory leak on error path Artem Bityutskiy
2012-05-20 5:49 ` Sidney Amani
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=1337340757-26127-1-git-send-email-dedekind1@gmail.com \
--to=dedekind1@gmail.com \
--cc=bengardiner@nanometrics.ca \
--cc=linux-mtd@lists.infradead.org \
--cc=seed95@gmail.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).