From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6GSu-0007FC-8M for qemu-devel@nongnu.org; Mon, 14 Nov 2016 07:34:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c6GSr-0003fn-5Z for qemu-devel@nongnu.org; Mon, 14 Nov 2016 07:34:24 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33498) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c6GSr-0003eb-0R for qemu-devel@nongnu.org; Mon, 14 Nov 2016 07:34:21 -0500 Received: by mail-pf0-f196.google.com with SMTP id 144so6173107pfv.0 for ; Mon, 14 Nov 2016 04:34:20 -0800 (PST) Message-ID: <5829af0f.84f4420a.a436f.4a73@mx.google.com> From: Li Qiang Date: Mon, 14 Nov 2016 07:32:57 -0500 In-Reply-To: <1479126778-125867-1-git-send-email-Qiang(liqiang6-s@360.cn)> References: <1479126778-125867-1-git-send-email-Qiang(liqiang6-s@360.cn)> Subject: [Qemu-devel] [PATCH 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 From: 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