From patchwork Wed Feb 8 02:42:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 9561685 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 4665C60547 for ; Wed, 8 Feb 2017 02:43:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36DCC28498 for ; Wed, 8 Feb 2017 02:43:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29C5C2849B; Wed, 8 Feb 2017 02:43:28 +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 7F44928498 for ; Wed, 8 Feb 2017 02:43:24 +0000 (UTC) Received: from localhost ([::1]:57403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbIE7-0006Oy-Jh for patchwork-qemu-devel@patchwork.kernel.org; Tue, 07 Feb 2017 21:43:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbIDs-0006Oq-LF for qemu-devel@nongnu.org; Tue, 07 Feb 2017 21:43:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cbIDp-0005mt-JZ for qemu-devel@nongnu.org; Tue, 07 Feb 2017 21:43:08 -0500 Received: from mail-ot0-x244.google.com ([2607:f8b0:4003:c0f::244]:36712) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cbIDp-0005mV-DS for qemu-devel@nongnu.org; Tue, 07 Feb 2017 21:43:05 -0500 Received: by mail-ot0-x244.google.com with SMTP id 36so16539863otx.3 for ; Tue, 07 Feb 2017 18:43:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:from:to:cc:subject:date; bh=7AASh8adsnz8TOn42FNrue4IIkUYiHA949FwRGXHIeI=; b=vcchQymF3YWFJQAEGoteeZTby/+p6A1S+/20+ax2uuxhz3r+kUDjBO9HkotNuccSuC yfyNHc9je3fMxCSFgBC3QdaRYnzleidgJYtQFZ4FmMSsFe/7s8vKMG+jC4/jEF40qOqf ugGuYxVgM3O2AXkHnwfhFAfJc4W38t8DCZDUlyuJaUKJXDXhtPrABF+N45Dw+TOOr3h1 SgZC3wP+P0x6kqpMYbh3T5b8Cs7tWjxaQxse4iO76k1JVxQ7IbSczjVqYbXdoyQ/rSJ0 uvbcYs8RX3/e4tRAg7KR93e2RHxuHrnUjY2URCteXOO0P/HthWQBcjJkjczy5dAX17g1 ffyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:from:to:cc:subject:date; bh=7AASh8adsnz8TOn42FNrue4IIkUYiHA949FwRGXHIeI=; b=Gi75tNDa9rtVIkkeaZwFq2DuVvzJs1KC5fpWLJvIWBxYLkGCzEwMlxD+4YXpFfaGr2 UdBrbWycT5PIWbtPBLk02lCV0MWPP7gaKsvri1Bt3gn/zTTS3yxU4AF/XnGck19CKu3m NAGgE56k4S1WD5J5v5r6QByl9sOvxZwzjL0kt/1LmsGJ878/sZVQ3W96sY4eqre7Od1l hz62rYcLpdBRIbqSv5rkJLnfKmFutqeksMIvx10tZ87JNc988ajE1aOI0zig+QBWGeug CMFOd6pjD8fjOf9CNh8pRiht88BLumRMgU/LLVsuyVtQLVjo9+QUxVHmvq82NwLu1NwF rcPg== X-Gm-Message-State: AMke39lCbbGPfwS2Yf3mi7Q1iw4PRFvSBME4yTtIxAmQbOcxLX/B6Y349iOhoYxCDgTcaw== X-Received: by 10.157.35.98 with SMTP id k31mr8731339otd.109.1486521784667; Tue, 07 Feb 2017 18:43:04 -0800 (PST) Received: from localhost.localdomain.localdomain ([104.192.110.250]) by smtp.gmail.com with ESMTPSA id o57sm3248464otb.28.2017.02.07.18.43.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Feb 2017 18:43:04 -0800 (PST) Message-ID: <589a85b8.3c2b9d0a.b8e6.1434@mx.google.com> X-Google-Original-Message-ID: <1486521775-11563-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: Tue, 7 Feb 2017 18:42:55 -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:4003:c0f::244 Subject: [Qemu-devel] [PATCH] usb: ehci: fix memory leak in ehci 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 usb_ehci_init function, it initializes 's->ipacket', but there is no corresponding function to free this. As the ehci can be hotplug and unplug, this will leak host memory leak. In order to make the hierarchy clean, we should add a ehci pci finalize function, then call the clean function in ehci device. Signed-off-by: Li Qiang --- hw/usb/hcd-ehci-pci.c | 9 +++++++++ hw/usb/hcd-ehci.c | 5 +++++ hw/usb/hcd-ehci.h | 1 + 3 files changed, 15 insertions(+) diff --git a/hw/usb/hcd-ehci-pci.c b/hw/usb/hcd-ehci-pci.c index 5657705..6dedcb8 100644 --- a/hw/usb/hcd-ehci-pci.c +++ b/hw/usb/hcd-ehci-pci.c @@ -89,6 +89,14 @@ static void usb_ehci_pci_init(Object *obj) usb_ehci_init(s, DEVICE(obj)); } +static void usb_ehci_pci_finalize(Object *obj) +{ + EHCIPCIState *i = PCI_EHCI(obj); + EHCIState *s = &i->ehci; + + usb_ehci_finalize(s); +} + static void usb_ehci_pci_exit(PCIDevice *dev) { EHCIPCIState *i = PCI_EHCI(dev); @@ -159,6 +167,7 @@ static const TypeInfo ehci_pci_type_info = { .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(EHCIPCIState), .instance_init = usb_ehci_pci_init, + .instance_finalize = usb_ehci_pci_finalize, .abstract = true, .class_init = ehci_class_init, }; diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index 7622a3a..50ef817 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -2545,6 +2545,11 @@ void usb_ehci_init(EHCIState *s, DeviceState *dev) &s->mem_ports); } +void usb_ehci_finalize(EHCIState *s) +{ + usb_packet_cleanup(&s->ipacket); +} + /* * vim: expandtab ts=4 */ diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h index 3fd7038..938d8aa 100644 --- a/hw/usb/hcd-ehci.h +++ b/hw/usb/hcd-ehci.h @@ -323,6 +323,7 @@ struct EHCIState { extern const VMStateDescription vmstate_ehci; void usb_ehci_init(EHCIState *s, DeviceState *dev); +void usb_ehci_finalize(EHCIState *s); void usb_ehci_realize(EHCIState *s, DeviceState *dev, Error **errp); void usb_ehci_unrealize(EHCIState *s, DeviceState *dev, Error **errp); void ehci_reset(void *opaque);