From patchwork Tue Nov 8 05:57:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 9416631 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A6F5A60512 for ; Tue, 8 Nov 2016 05:58:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B81228BD2 for ; Tue, 8 Nov 2016 05:58:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E53D28BDB; Tue, 8 Nov 2016 05:58:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 841C628BD2 for ; Tue, 8 Nov 2016 05:58:36 +0000 (UTC) Received: from localhost ([::1]:58497 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c3zQY-0007PR-OY for patchwork-qemu-devel@patchwork.kernel.org; Tue, 08 Nov 2016 00:58:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c3zQK-0007PM-MQ for qemu-devel@nongnu.org; Tue, 08 Nov 2016 00:58:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c3zQH-0002mv-Hc for qemu-devel@nongnu.org; Tue, 08 Nov 2016 00:58:20 -0500 Received: from mail-it0-x243.google.com ([2607:f8b0:4001:c0b::243]:35265) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c3zQH-0002mj-DB for qemu-devel@nongnu.org; Tue, 08 Nov 2016 00:58:17 -0500 Received: by mail-it0-x243.google.com with SMTP id b123so8907160itb.2 for ; Mon, 07 Nov 2016 21:58:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:from:to:cc:subject:date; bh=jEoKI4Z/0+Djz0U2svT/9CamCwUz4PEbba0kE9UCrEI=; b=RXdVhUnPADw89Nas5TAoRKz9nOAtWzHffkmxsf8FWNMOHkDzd7Z391dVWc0PMZptlZ vth/xUDh0EwkJImz/rSSTPvMuCjFvtTnH5wFhYBsRreNLvztGzw2GF5TiPVcEiSgaJhc Dc1hN1UKNfbeXUhY31/ErcVt30/h4qzdXWJD3GegqlsqNx44ygcZheEorVieVzxkoUND c3S9mhUlio9eiJZc4yEYkENPuTldi7WTUv6aKsqkctq26ptps9tKQ92ELLzQy8dx5kE9 eKowpkLffBKN9uBWiDk4/EGVEOlwxXCr8i6BWhchcdXh/zXc/eKpGrZIFMS4ykfBWgCl UL4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:from:to:cc:subject:date; bh=jEoKI4Z/0+Djz0U2svT/9CamCwUz4PEbba0kE9UCrEI=; b=JUj4XMz7TA1mC1LDB9EmbyDBWvqP+GxT0F0R/x9TvdEVEPjhM0+BcPbVrt5ucyEacD SgObRuGbZLuzk04Sab9BCKCriKUGx9+IALoQ99FCkK2xan1vLKg84lq3m6XjGs22k6eK beQD/v0YngnwzuzcYnDQgWdxOBu/RKWYhhGOR6rUe+SazAFm7lOOp7q/VCJEKixVInTH wDCVKrOOEzmm2r2pYZzM5MUnY8kzxOBBJTz7iRP5D8G4AOUBYHISbf0uCxn95CM+rYsM +GY0ptyVQbALIVmhPFoTn8xbrLF5LBvq/zp+6BaFlELZ92Y7pNSMqXhVyNMHshrAHbSd f5bg== X-Gm-Message-State: ABUngvfcChCJGsD105mOOfJUIqi56ZvO2nXjZFxvDONqBTfm2m3u+rEcF+fLLyG9PJhg8w== X-Received: by 10.107.50.75 with SMTP id y72mr13872617ioy.22.1478584695069; Mon, 07 Nov 2016 21:58:15 -0800 (PST) Received: from localhost.localdomain.localdomain ([104.192.110.250]) by smtp.gmail.com with ESMTPSA id j199sm7286083ioj.16.2016.11.07.21.58.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Nov 2016 21:58:14 -0800 (PST) Message-ID: <58216976.d0236b0a.77b99.bcd6@mx.google.com> X-Google-Original-Message-ID: <1478584666-14510-1-git-send-email-Qiang(liqiang6-s@360.cn)> From: Li Qiang X-Google-Original-From: Li Qiang(liqiang6-s@360.cn) To: kraxel@redhat.com, qemu-devel@nongnu.org Date: Mon, 7 Nov 2016 21:57:46 -0800 X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4001:c0b::243 Subject: [Qemu-devel] [PATCH] usbredir: free vm_change_state_handler in usbredir destroy dispatch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Li Qiang In usbredir destroy dispatch function, it doesn't free the vm change state handler once registered in usbredir_realize function. This will lead a memory leak issue. This patch avoid this. Signed-off-by: Li Qiang Reviewed-by: Marc-André Lureau --- hw/usb/redirect.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c index 528081e..a657237 100644 --- a/hw/usb/redirect.c +++ b/hw/usb/redirect.c @@ -132,6 +132,7 @@ struct USBRedirDevice { struct usbredirfilter_rule *filter_rules; int filter_rules_count; int compatible_speedmask; + VMChangeStateEntry *vmstate; }; #define TYPE_USB_REDIR "usb-redir" @@ -1411,7 +1412,8 @@ static void usbredir_realize(USBDevice *udev, Error **errp) usbredir_chardev_read, usbredir_chardev_event, dev, NULL, true); - qemu_add_vm_change_state_handler(usbredir_vm_state_change, dev); + dev->vmstate = + qemu_add_vm_change_state_handler(usbredir_vm_state_change, dev); } static void usbredir_cleanup_device_queues(USBRedirDevice *dev) @@ -1450,6 +1452,7 @@ static void usbredir_handle_destroy(USBDevice *udev) } free(dev->filter_rules); + qemu_del_vm_change_state_handler(dev->vmstate); } static int usbredir_check_filter(USBRedirDevice *dev)