From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6TGJ-0004rv-LY for qemu-devel@nongnu.org; Mon, 14 Nov 2016 21:14:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c6TGI-0006ib-Qo for qemu-devel@nongnu.org; Mon, 14 Nov 2016 21:14:15 -0500 Received: from mail-it0-x244.google.com ([2607:f8b0:4001:c0b::244]:33173) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c6TGI-0006iS-Lf for qemu-devel@nongnu.org; Mon, 14 Nov 2016 21:14:14 -0500 Received: by mail-it0-x244.google.com with SMTP id c20so16289360itb.0 for ; Mon, 14 Nov 2016 18:14:14 -0800 (PST) From: Li Qiang Date: Mon, 14 Nov 2016 21:13:52 -0500 Message-Id: <1479176033-36604-3-git-send-email-liq3ea@gmail.com> In-Reply-To: <1479176033-36604-1-git-send-email-liq3ea@gmail.com> References: <1479176033-36604-1-git-send-email-liq3ea@gmail.com> Subject: [Qemu-devel] [PATCH v2 2/3] 9pfs: add cleanup operation for handle 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 handle backend dirver, it allocates a handle_data struct and opens a mount file. We should free these resources when the 9pfs device is unrealized. This is what this patch does. Signed-off-by: Li Qiang --- hw/9pfs/9p-handle.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c index 3d77594..9b50f40 100644 --- a/hw/9pfs/9p-handle.c +++ b/hw/9pfs/9p-handle.c @@ -649,6 +649,13 @@ out: return ret; } +static void handle_cleanup(FsContext *ctx) +{ + struct handle_data *data = ctx->private; + close(data->mountfd); + g_free(data); +} + static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) { const char *sec_model = qemu_opt_get(opts, "security_model"); @@ -671,6 +678,7 @@ static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse) FileOperations handle_ops = { .parse_opts = handle_parse_opts, .init = handle_init, + .cleanup = handle_cleanup, .lstat = handle_lstat, .readlink = handle_readlink, .close = handle_close, -- 1.8.3.1