nbd:fix memory leak in nbd_get_socket()
authorSun Ke <sunke32@huawei.com>
Tue, 19 Nov 2019 06:09:11 +0000 (14:09 +0800)
committerJens Axboe <axboe@kernel.dk>
Tue, 19 Nov 2019 16:23:26 +0000 (09:23 -0700)
Before returning NULL, put the sock first.

Cc: stable@vger.kernel.org
Fixes: cf1b2326b734 ("nbd: verify socket is supported during setup")
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Mike Christie <mchristi@redhat.com>
Signed-off-by: Sun Ke <sunke32@huawei.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/nbd.c

index a94ee45..19e7599 100644 (file)
@@ -993,6 +993,7 @@ static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd,
        if (sock->ops->shutdown == sock_no_shutdown) {
                dev_err(disk_to_dev(nbd->disk), "Unsupported socket: shutdown callout must be supported.\n");
                *err = -EINVAL;
        if (sock->ops->shutdown == sock_no_shutdown) {
                dev_err(disk_to_dev(nbd->disk), "Unsupported socket: shutdown callout must be supported.\n");
                *err = -EINVAL;
+               sockfd_put(sock);
                return NULL;
        }
 
                return NULL;
        }