summaryrefslogtreecommitdiff
path: root/drivers/block
diff options
context:
space:
mode:
authorNavid Emamdoost <navid.emamdoost@gmail.com>2019-09-23 15:09:58 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-12-01 09:17:38 +0100
commit344966da99c962bea479298e4d3744e0c6a513f1 (patch)
treede74df81fdec692a8a2f30e0afd6fb8fe9347654 /drivers/block
parented7a3dde0aa224051c6455fce3755bf48c062178 (diff)
nbd: prevent memory leak
commit 03bf73c315edca28f47451913177e14cd040a216 upstream. In nbd_add_socket when krealloc succeeds, if nsock's allocation fail the reallocted memory is leak. The correct behaviour should be assigning the reallocted memory to config->socks right after success. Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/nbd.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index d76840873420..996b1ef5f076 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -984,14 +984,15 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
sockfd_put(sock);
return -ENOMEM;
}
+
+ config->socks = socks;
+
nsock = kzalloc(sizeof(struct nbd_sock), GFP_KERNEL);
if (!nsock) {
sockfd_put(sock);
return -ENOMEM;
}
- config->socks = socks;
-
nsock->fallback_index = -1;
nsock->dead = false;
mutex_init(&nsock->tx_lock);