mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-11-08 10:31:43 +01:00
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 <[email protected]> Signed-off-by: Navid Emamdoost <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
This commit is contained in:
1 parent
866ca95da5
commit
03bf73c315
1 file changed
+3
-2
+3
-2
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user