Skip to content

Commit d710e1e

Browse files
Li Qiangkraxel
Li Qiang
authored andcommitted
usb: ehci: fix memory leak in ehci
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]>
1 parent 56f9e46 commit d710e1e

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

hw/usb/hcd-ehci-pci.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ static void usb_ehci_pci_init(Object *obj)
8989
usb_ehci_init(s, DEVICE(obj));
9090
}
9191

92+
static void usb_ehci_pci_finalize(Object *obj)
93+
{
94+
EHCIPCIState *i = PCI_EHCI(obj);
95+
EHCIState *s = &i->ehci;
96+
97+
usb_ehci_finalize(s);
98+
}
99+
92100
static void usb_ehci_pci_exit(PCIDevice *dev)
93101
{
94102
EHCIPCIState *i = PCI_EHCI(dev);
@@ -159,6 +167,7 @@ static const TypeInfo ehci_pci_type_info = {
159167
.parent = TYPE_PCI_DEVICE,
160168
.instance_size = sizeof(EHCIPCIState),
161169
.instance_init = usb_ehci_pci_init,
170+
.instance_finalize = usb_ehci_pci_finalize,
162171
.abstract = true,
163172
.class_init = ehci_class_init,
164173
};

hw/usb/hcd-ehci.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,6 +2545,11 @@ void usb_ehci_init(EHCIState *s, DeviceState *dev)
25452545
&s->mem_ports);
25462546
}
25472547

2548+
void usb_ehci_finalize(EHCIState *s)
2549+
{
2550+
usb_packet_cleanup(&s->ipacket);
2551+
}
2552+
25482553
/*
25492554
* vim: expandtab ts=4
25502555
*/

hw/usb/hcd-ehci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ struct EHCIState {
323323
extern const VMStateDescription vmstate_ehci;
324324

325325
void usb_ehci_init(EHCIState *s, DeviceState *dev);
326+
void usb_ehci_finalize(EHCIState *s);
326327
void usb_ehci_realize(EHCIState *s, DeviceState *dev, Error **errp);
327328
void usb_ehci_unrealize(EHCIState *s, DeviceState *dev, Error **errp);
328329
void ehci_reset(void *opaque);

0 commit comments

Comments
 (0)