]> Git Repo - qemu.git/commitdiff
usb: ehci: fix memory leak in ehci
authorLi Qiang <[email protected]>
Wed, 8 Feb 2017 02:42:55 +0000 (18:42 -0800)
committerGerd Hoffmann <[email protected]>
Tue, 21 Feb 2017 07:11:42 +0000 (08:11 +0100)
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 <[email protected]>
Message-id: 589a85b8.3c2b9d0a[email protected]
Signed-off-by: Gerd Hoffmann <[email protected]>
hw/usb/hcd-ehci-pci.c
hw/usb/hcd-ehci.c
hw/usb/hcd-ehci.h

index 56577051e2bebde93aea578d3ff43c7badd2579b..6dedcb89895d34ad848d98ff13d46ff89b572e8f 100644 (file)
@@ -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,
 };
index 7622a3ae7250c7eacd7f08427f0df8c40720f3de..50ef817f93d99ccab0bb26d0e389b3f1a78a843c 100644 (file)
@@ -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
  */
index 3fd7038658eaa40a3c0512805cd2286a95e3f646..938d8aa28401cfb3e11b9775934746b9aebf8040 100644 (file)
@@ -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);
This page took 0.032475 seconds and 4 git commands to generate.