From: Chaitanya Kulkarni <Chaitanya.Kulkarni@wdc.com>
To: Zheng Bin <zhengbin13@huawei.com>,
"josef@toxicpanda.com" <josef@toxicpanda.com>,
"axboe@kernel.dk" <axboe@kernel.dk>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"nbd@other.debian.org" <nbd@other.debian.org>
Cc: "yi.zhang@huawei.com" <yi.zhang@huawei.com>
Subject: Re: [PATCH] nbd: Fix memory leak in nbd_add_socket
Date: Thu, 25 Jun 2020 00:16:33 +0000 [thread overview]
Message-ID: <BYAPR04MB4965BCC5D59A22A417274A5486920@BYAPR04MB4965.namprd04.prod.outlook.com> (raw)
In-Reply-To: 20200612090437.77977-1-zhengbin13@huawei.com
On 6/12/20 1:57 AM, Zheng Bin wrote:
> nbd_add_socket
> socks = krealloc(num_connections+1) -->if num_connections is 0, alloc 1
> nsock = kzalloc -->If fail, will return
>
> nbd_config_put
> if (config->num_connections) -->0, not free
> kfree(config->socks)
>
> Thus memleak happens, this patch fixes that.
>
> Signed-off-by: Zheng Bin<zhengbin13@huawei.com>
Not an nbd expert but wouldn't it be easier use following which matches
the + 1 in the nbd_add_socket() :-
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 01794cd2b6ca..e67c790039c9 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1209,9 +1209,9 @@ static void nbd_config_put(struct nbd_device *nbd)
device_remove_file(disk_to_dev(nbd->disk),
&pid_attr);
nbd->task_recv = NULL;
nbd_clear_sock(nbd);
- if (config->num_connections) {
+ if (config->num_connections + 1) {
int i;
- for (i = 0; i < config->num_connections; i++) {
+ for (i = 0; i < (config->num_connections + 1);
i++) {
sockfd_put(config->socks[i]->sock);
kfree(config->socks[i]);
}
next prev parent reply other threads:[~2020-06-25 0:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-12 9:04 [PATCH] nbd: Fix memory leak in nbd_add_socket Zheng Bin
2020-06-25 0:16 ` Chaitanya Kulkarni [this message]
2020-06-28 15:58 ` Eric Biggers
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=BYAPR04MB4965BCC5D59A22A417274A5486920@BYAPR04MB4965.namprd04.prod.outlook.com \
--to=chaitanya.kulkarni@wdc.com \
--cc=axboe@kernel.dk \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=nbd@other.debian.org \
--cc=yi.zhang@huawei.com \
--cc=zhengbin13@huawei.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).