diff mbox

[v2,3/3] 9pfs: add cleanup operation for proxy backend driver

Message ID 1479176033-36604-4-git-send-email-liq3ea@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Li Qiang Nov. 15, 2016, 2:13 a.m. UTC
In the init operation of proxy backend dirver, it allocates a
V9fsProxy struct and some other resources. We should free these
resources when the 9pfs device is unrealized. This is what this
patch does.

Signed-off-by: Li Qiang <liq3ea@gmail.com>
---
 hw/9pfs/9p-proxy.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Greg Kurz Nov. 15, 2016, 10:26 a.m. UTC | #1
On Mon, 14 Nov 2016 21:13:53 -0500
Li Qiang <liq3ea@gmail.com> wrote:

> In the init operation of proxy backend dirver, it allocates a
> V9fsProxy struct and some other resources. We should free these
> resources when the 9pfs device is unrealized. This is what this
> patch does.
> 
> Signed-off-by: Li Qiang <liq3ea@gmail.com>
> ---

Oops I gave my R-b tag a bit to fast because...

>  hw/9pfs/9p-proxy.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c
> index f2417b7..4b22f57 100644
> --- a/hw/9pfs/9p-proxy.c
> +++ b/hw/9pfs/9p-proxy.c
> @@ -1168,9 +1168,19 @@ static int proxy_init(FsContext *ctx)
>      return 0;
>  }
>  
> +static void proxy_cleanup(FsContext *ctx)
> +{
> +    V9fsProxy *proxy = ctx->private;
> +    close(proxy->sockfd);

... this should only be done if QEMU opened the fd (i.e. V9FS_PROXY_SOCK_NAME)

> +    g_free(proxy->in_iovec.iov_base);
> +    g_free(proxy->out_iovec.iov_base);
> +    g_free(proxy);
> +}
> +
>  FileOperations proxy_ops = {
>      .parse_opts   = proxy_parse_opts,
>      .init         = proxy_init,
> +    .cleanup      = proxy_cleanup,
>      .lstat        = proxy_lstat,
>      .readlink     = proxy_readlink,
>      .close        = proxy_close,
diff mbox

Patch

diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c
index f2417b7..4b22f57 100644
--- a/hw/9pfs/9p-proxy.c
+++ b/hw/9pfs/9p-proxy.c
@@ -1168,9 +1168,19 @@  static int proxy_init(FsContext *ctx)
     return 0;
 }
 
+static void proxy_cleanup(FsContext *ctx)
+{
+    V9fsProxy *proxy = ctx->private;
+    close(proxy->sockfd);
+    g_free(proxy->in_iovec.iov_base);
+    g_free(proxy->out_iovec.iov_base);
+    g_free(proxy);
+}
+
 FileOperations proxy_ops = {
     .parse_opts   = proxy_parse_opts,
     .init         = proxy_init,
+    .cleanup      = proxy_cleanup,
     .lstat        = proxy_lstat,
     .readlink     = proxy_readlink,
     .close        = proxy_close,