From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7DCi-0005RT-Ng for qemu-devel@nongnu.org; Wed, 16 Nov 2016 22:17:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c7DCf-0004y2-K4 for qemu-devel@nongnu.org; Wed, 16 Nov 2016 22:17:36 -0500 Received: from mail-it0-x243.google.com ([2607:f8b0:4001:c0b::243]:34299) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c7DCf-0004xc-Ct for qemu-devel@nongnu.org; Wed, 16 Nov 2016 22:17:33 -0500 Received: by mail-it0-x243.google.com with SMTP id o1so11990833ito.1 for ; Wed, 16 Nov 2016 19:17:33 -0800 (PST) From: Li Qiang Date: Wed, 16 Nov 2016 22:16:56 -0500 Message-Id: <1479352616-64991-5-git-send-email-liq3ea@gmail.com> In-Reply-To: <1479352616-64991-1-git-send-email-liq3ea@gmail.com> References: <1479352616-64991-1-git-send-email-liq3ea@gmail.com> Subject: [Qemu-devel] [PATCH v3 4/4] 9pfs: add cleanup operation for proxy backend driver List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: groug@kaod.org, qemu-devel@nongnu.org Cc: liqiang6-s@360.cn, Li Qiang 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 --- Changes since the v2: -only close proxy->sockfd if QEMU opened the fd -do the cleanup work in reverse order hw/9pfs/9p-proxy.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c index f2417b7..f4aa7a9 100644 --- a/hw/9pfs/9p-proxy.c +++ b/hw/9pfs/9p-proxy.c @@ -1168,9 +1168,22 @@ static int proxy_init(FsContext *ctx) return 0; } +static void proxy_cleanup(FsContext *ctx) +{ + V9fsProxy *proxy = ctx->private; + + g_free(proxy->out_iovec.iov_base); + g_free(proxy->in_iovec.iov_base); + if (ctx->export_flags & V9FS_PROXY_SOCK_NAME) { + close(proxy->sockfd); + } + 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, -- 1.8.3.1