Skip to content

Commit

Permalink
usb: ehci: fix memory leak in ehci
Browse files Browse the repository at this point in the history
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: [email protected]
Signed-off-by: Gerd Hoffmann <[email protected]>
  • Loading branch information
Li Qiang authored and kraxel committed Feb 21, 2017
1 parent 56f9e46 commit d710e1e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions hw/usb/hcd-ehci-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
};
Expand Down
5 changes: 5 additions & 0 deletions hw/usb/hcd-ehci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
1 change: 1 addition & 0 deletions hw/usb/hcd-ehci.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d710e1e

Please sign in to comment.