From nobody Tue Apr 23 19:39:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486521847614419.28521170660804; Tue, 7 Feb 2017 18:44:07 -0800 (PST) Received: from localhost ([::1]:57404 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbIEk-0006gb-50 for importer@patchew.org; Tue, 07 Feb 2017 21:44:02 -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) 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) 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) 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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)); } =20 +static void usb_ehci_pci_finalize(Object *obj) +{ + EHCIPCIState *i =3D PCI_EHCI(obj); + EHCIState *s =3D &i->ehci; + + usb_ehci_finalize(s); +} + static void usb_ehci_pci_exit(PCIDevice *dev) { EHCIPCIState *i =3D PCI_EHCI(dev); @@ -159,6 +167,7 @@ static const TypeInfo ehci_pci_type_info =3D { .parent =3D TYPE_PCI_DEVICE, .instance_size =3D sizeof(EHCIPCIState), .instance_init =3D usb_ehci_pci_init, + .instance_finalize =3D usb_ehci_pci_finalize, .abstract =3D true, .class_init =3D 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); } =20 +void usb_ehci_finalize(EHCIState *s) +{ + usb_packet_cleanup(&s->ipacket); +} + /* * vim: expandtab ts=3D4 */ 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; =20 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); --=20 1.8.3.1