[PATCH 5.4 18/50] um: virtio_uml: fix memory leak on init failures
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: 2021-09-24 12:53:39
Also in:
lkml
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: 2021-09-24 12:53:39
Also in:
lkml
From: Johannes Berg <redacted>
commit 7ad28e0df7ee9dbcb793bb88dd81d4d22bb9a10e upstream.
If initialization fails, e.g. because the connection failed,
we leak the 'vu_dev'. Fix that. Reported by smatch.
Fixes: 5d38f324993f ("um: drivers: Add virtio vhost-user driver")
Signed-off-by: Johannes Berg <redacted>
Acked-By: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
arch/um/drivers/virtio_uml.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
--- a/arch/um/drivers/virtio_uml.c
+++ b/arch/um/drivers/virtio_uml.c@@ -994,7 +994,7 @@ static int virtio_uml_probe(struct platf rc = os_connect_socket(pdata->socket_path); } while (rc == -EINTR); if (rc < 0) - return rc; + goto error_free; vu_dev->sock = rc; rc = vhost_user_init(vu_dev);
@@ -1010,6 +1010,8 @@ static int virtio_uml_probe(struct platf error_init: os_close_file(vu_dev->sock); +error_free: + kfree(vu_dev); return rc; }