diff options
author | Navid Emamdoost <navid.emamdoost@gmail.com> | 2019-09-23 23:09:58 +0300 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2019-11-21 21:33:41 +0300 |
commit | 03bf73c315edca28f47451913177e14cd040a216 (patch) | |
tree | be6c1803a0475f2654db1dba73c30581d2a4a319 /drivers/block | |
parent | 866ca95da5e5c4fad59f1b08254168284bd6a911 (diff) | |
download | linux-03bf73c315edca28f47451913177e14cd040a216.tar.xz |
nbd: prevent memory leak
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>
Diffstat (limited to 'drivers/block')
-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 ac07e8c94c79..f471142d264d 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1004,14 +1004,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); |