3ec3496
From 898ae90a44551d25b8e956fd87372d303c82fe68 Mon Sep 17 00:00:00 2001
3ec3496
From: Li Qiang <liq3ea@gmail.com>
3ec3496
Date: Wed, 23 Nov 2016 13:53:34 +0100
3ec3496
Subject: [PATCH] 9pfs: add cleanup operation for proxy backend driver
3ec3496
3ec3496
In the init operation of proxy backend dirver, it allocates a
3ec3496
V9fsProxy struct and some other resources. We should free these
3ec3496
resources when the 9pfs device is unrealized. This is what this
3ec3496
patch does.
3ec3496
3ec3496
Signed-off-by: Li Qiang <liq3ea@gmail.com>
3ec3496
Reviewed-by: Greg Kurz <groug@kaod.org>
3ec3496
Signed-off-by: Greg Kurz <groug@kaod.org>
3ec3496
---
3ec3496
 hw/9pfs/virtio-9p-proxy.c |   13 +++++++++++++
3ec3496
 1 files changed, 13 insertions(+), 0 deletions(-)
3ec3496
3ec3496
diff --git a/hw/9pfs/virtio-9p-proxy.c b/hw/9pfs/virtio-9p-proxy.c
3ec3496
index f2417b7..f4aa7a9 100644
3ec3496
--- a/hw/9pfs/virtio-9p-proxy.c
3ec3496
+++ b/hw/9pfs/virtio-9p-proxy.c
3ec3496
@@ -1168,9 +1168,22 @@ static int proxy_init(FsContext *ctx)
3ec3496
     return 0;
3ec3496
 }
3ec3496
 
3ec3496
+static void proxy_cleanup(FsContext *ctx)
3ec3496
+{
3ec3496
+    V9fsProxy *proxy = ctx->private;
3ec3496
+
3ec3496
+    g_free(proxy->out_iovec.iov_base);
3ec3496
+    g_free(proxy->in_iovec.iov_base);
3ec3496
+    if (ctx->export_flags & V9FS_PROXY_SOCK_NAME) {
3ec3496
+        close(proxy->sockfd);
3ec3496
+    }
3ec3496
+    g_free(proxy);
3ec3496
+}
3ec3496
+
3ec3496
 FileOperations proxy_ops = {
3ec3496
     .parse_opts   = proxy_parse_opts,
3ec3496
     .init         = proxy_init,
3ec3496
+    .cleanup      = proxy_cleanup,
3ec3496
     .lstat        = proxy_lstat,
3ec3496
     .readlink     = proxy_readlink,
3ec3496
     .close        = proxy_close,
3ec3496
-- 
3ec3496
1.7.0.4
3ec3496