Received: from eggs.gnu.org ([2001:4830:134:3::10]:41042) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c7DCa-0005KL-Uh for qemu-devel@nongnu.org; Wed, 16 Nov 2016 22:17:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c7DCa-0004vC-2X for qemu-devel@nongnu.org; Wed, 16 Nov 2016 22:17:28 -0500 Received: from mail-it0-x242.google.com ([2607:f8b0:4001:c0b::242]:36208) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c7DCZ-0004uq-SO for qemu-devel@nongnu.org; Wed, 16 Nov 2016 22:17:28 -0500 Received: by mail-it0-x242.google.com with SMTP id n68so11932453itn.3 for ; Wed, 16 Nov 2016 19:17:27 -0800 (PST) From: Li Qiang Date: Wed, 16 Nov 2016 22:16:55 -0500 Message-Id: <1479352616-64991-4-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 3/4] 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/9pfs/9p-handle.c b/hw/9pfs/9p-handle.c index 3d77594..1687661 100644 --- a/hw/9pfs/9p-handle.c +++ b/hw/9pfs/9p-handle.c @@ -649,6 +649,14 @@ 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 +679,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