[PATCH AUTOSEL 4.19 5/5] vhost/test: fix memory leak of vhost virtqueues

From: Sasha Levin
Date: Sat Jan 22 2022 - 19:15:18 EST


From: Xianting Tian <xianting.tian@xxxxxxxxxxxxxxxxx>

[ Upstream commit 080063920777af65105e5953e2851e036376e3ea ]

We need free the vqs in .release(), which are allocated in .open().

Signed-off-by: Xianting Tian <xianting.tian@xxxxxxxxxxxxxxxxx>
Link: https://lore.kernel.org/r/20211228030924.3468439-1-xianting.tian@xxxxxxxxxxxxxxxxx
Signed-off-by: Michael S. Tsirkin <mst@xxxxxxxxxx>
Acked-by: Jason Wang <jasowang@xxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
drivers/vhost/test.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/vhost/test.c b/drivers/vhost/test.c
index 55090d9f9de0d..2d6abe1c0dbec 100644
--- a/drivers/vhost/test.c
+++ b/drivers/vhost/test.c
@@ -167,6 +167,7 @@ static int vhost_test_release(struct inode *inode, struct file *f)
/* We do an extra flush before freeing memory,
* since jobs can re-queue themselves. */
vhost_test_flush(n);
+ kfree(n->dev.vqs);
kfree(n);
return 0;
}
--
2.34.1