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] nbd: fix possible memory leak
Date: Tue, 13 Jan 2015 22:49:17 +0530 [thread overview]
Message-ID: <1421169557-18549-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>
---
Hi Paul,
after seeing your mail about maintainers, just started to see the code.
this patch is one way, another way can be to bring the kcalloc part below these checks.
drivers/block/nbd.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 4bc2a5c..13ea239 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -822,11 +822,15 @@ static int __init nbd_init(void)
max_part = (1UL << part_shift) - 1;
}
- if ((1UL << part_shift) > DISK_MAX_PARTS)
- return -EINVAL;
+ if ((1UL << part_shift) > DISK_MAX_PARTS) {
+ err = -EINVAL;
+ goto out_free;
+ }
- if (nbds_max > 1UL << (MINORBITS - part_shift))
- return -EINVAL;
+ if (nbds_max > 1UL << (MINORBITS - part_shift)) {
+ err = -EINVAL;
+ goto out_free;
+ }
for (i = 0; i < nbds_max; i++) {
struct gendisk *disk = alloc_disk(1 << part_shift);
@@ -889,6 +893,7 @@ out:
blk_cleanup_queue(nbd_dev[i].disk->queue);
put_disk(nbd_dev[i].disk);
}
+out_free:
kfree(nbd_dev);
return err;
}
--
1.8.1.2
next reply other threads:[~2015-01-13 17:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-13 17:19 Sudip Mukherjee [this message]
2015-01-26 17:00 ` Paul Clements
2015-02-12 13:37 [GIT PULL] NBD fixes Markus Pargmann
2015-02-12 13:37 ` [PATCH] nbd: fix possible memory leak Markus Pargmann
2015-03-05 8:09 [PULL v2] NBD fixes Markus Pargmann
2015-03-05 8:09 ` [PATCH] nbd: fix possible memory leak 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=1421169557-18549-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®