nbd: prevent memory leak
Subsystems (2)
PATCH 1/1 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.
--- drivers/block/nbd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/block/nbd.c +3 -2
@@ -987,14 +987,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);
Signature · 1 line
2.17.1
Quoted 7 lines · Navid Emamdoost
In
nbd_add_socketwhen krealloc succeeds, if nsock's allocation fail the reallocted memory is leak. The correct behaviour should be assigning the reallocted memory toconfig->socksright after success.Signed-off-by Navid Emamdoost <[email protected]>---
Would you please review this patch?
Thanks,
Quoted 28 lines
drivers/block/nbd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/block/nbd.c +3
-3@@ -987,14 +987,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); --2.17.1
Signature · 1 line
Navid.
Quoted 6 lines · Navid Emamdoost
In
nbd_add_socketwhen krealloc succeeds, if nsock's allocation fail the reallocted memory is leak. The correct behaviour should be assigning the reallocted memory toconfig->socksright after success.Signed-off-by Navid Emamdoost <[email protected]>---
Thanks,
Josef
Jens Axboe
maintainerQuoted 9 lines · Josef Bacik
Quoted 6 lines · Navid Emamdoost
In
nbd_add_socketwhen krealloc succeeds, if nsock's allocation fail the reallocted memory is leak. The correct behaviour should be assigning the reallocted memory toconfig->socksright after success.Signed-off-by Navid Emamdoost <[email protected]>---
Reviewed-by Josef Bacik <[email protected]>
Now applied, thanks.
Signature · 1 line
Jens Axboe