diff options
author | Navid Emamdoost <navid.emamdoost@gmail.com> | 2019-09-23 23:09:58 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2019-11-29 12:09:47 +0300 |
commit | abf404dfa5c5e05138088e072175485c12fbfbf9 (patch) | |
tree | a5ef1178b18f42ed4ef6715059bdf51c60c89397 | |
parent | 7b77206ad5b09d3895a03cc608ca82d5aecde0f2 (diff) | |
download | linux-abf404dfa5c5e05138088e072175485c12fbfbf9.tar.xz |
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>
-rw-r--r-- | drivers/block/nbd.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 19e75999bb15..57532465fb83 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1032,14 +1032,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); |