From: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
To: Paul Clements <Paul.Clements@steeleye.com>
Cc: Sudip Mukherjee <sudipm.mukherjee@gmail.com>,
nbd-general@lists.sourceforge.net, linux-kernel@vger.kernel.org
Subject: [PATCH v2] nbd: fix possible memory leak
Date: Tue, 27 Jan 2015 18:08:22 +0530 [thread overview]
Message-ID: <1422362302-25252-1-git-send-email-sudipm.mukherjee@gmail.com> (raw)
we have already allocated memory for nbd_dev, but we were not
releasing that memory and just returning the error value.
Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---
v2: moved kcalloc after the returns.
drivers/block/nbd.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 4bc2a5c..db93c75 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -803,10 +803,6 @@ static int __init nbd_init(void)
return -EINVAL;
}
- nbd_dev = kcalloc(nbds_max, sizeof(*nbd_dev), GFP_KERNEL);
- if (!nbd_dev)
- return -ENOMEM;
-
part_shift = 0;
if (max_part > 0) {
part_shift = fls(max_part);
@@ -827,6 +823,10 @@ static int __init nbd_init(void)
if (nbds_max > 1UL << (MINORBITS - part_shift))
return -EINVAL;
+
+ nbd_dev = kcalloc(nbds_max, sizeof(*nbd_dev), GFP_KERNEL);
+ if (!nbd_dev)
+ return -ENOMEM;
for (i = 0; i < nbds_max; i++) {
struct gendisk *disk = alloc_disk(1 << part_shift);
--
1.8.1.2
next reply other threads:[~2015-01-27 12:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-27 12:38 Sudip Mukherjee [this message]
2015-01-27 14:16 ` Paul Clements
2015-01-28 20:13 ` [Nbd] " Markus Pargmann
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=1422362302-25252-1-git-send-email-sudipm.mukherjee@gmail.com \
--to=sudipm.mukherjee@gmail.com \
--cc=Paul.Clements@steeleye.com \
--cc=linux-kernel@vger.kernel.org \
--cc=nbd-general@lists.sourceforge.net \
/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
all inboxes | Powered by JetHome®