Skip to content

Commit 03bf73c

Browse files
Navidemaxboe
authored andcommitted
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]>
1 parent 866ca95 commit 03bf73c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/block/nbd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,14 +1004,15 @@ static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
10041004
sockfd_put(sock);
10051005
return -ENOMEM;
10061006
}
1007+
1008+
config->socks = socks;
1009+
10071010
nsock = kzalloc(sizeof(struct nbd_sock), GFP_KERNEL);
10081011
if (!nsock) {
10091012
sockfd_put(sock);
10101013
return -ENOMEM;
10111014
}
10121015

1013-
config->socks = socks;
1014-
10151016
nsock->fallback_index = -1;
10161017
nsock->dead = false;
10171018
mutex_init(&nsock->tx_lock);

0 commit comments

Comments
 (0)