From 1fea734e540ed84e93356381db9d694659477132 Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Sat, 10 Feb 2018 12:03:58 +0100 Subject: libpayload/drivers/usb: Fix leaks Don't leak buffers on device detach. Tested on qemu using: qemu-system-x86_64 -bios build/coreboot.rom -M pc -m 2048 -usb \ -device usb-ehci,id=ehci -device usb-mouse -device usb-audio,bus=usb-bus.0 \ -device usb-bt-dongle,bus=usb-bus.0 -device usb-kbd Change-Id: Ib2d80dd4590aa0dacdf2da3b614c6505c931d0be Signed-off-by: Patrick Rudolph Reviewed-on: https://review.coreboot.org/23689 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- payloads/libpayload/drivers/usb/usb.c | 7 +++++++ payloads/libpayload/drivers/usb/usb_dev.c | 5 ++--- payloads/libpayload/drivers/usb/usbhid.c | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'payloads/libpayload/drivers/usb') diff --git a/payloads/libpayload/drivers/usb/usb.c b/payloads/libpayload/drivers/usb/usb.c index a6d5d43c23..62604a27ca 100644 --- a/payloads/libpayload/drivers/usb/usb.c +++ b/payloads/libpayload/drivers/usb/usb.c @@ -638,8 +638,15 @@ usb_detach_device(hci_t *controller, int devno) been called yet by the usb class driver */ if (controller->devices[devno]) { controller->devices[devno]->destroy (controller->devices[devno]); + if (controller->destroy_device) controller->destroy_device(controller, devno); + + free(controller->devices[devno]->descriptor); + controller->devices[devno]->descriptor = NULL; + free(controller->devices[devno]->configuration); + controller->devices[devno]->configuration = NULL; + /* Tear down the device itself *after* destroy_device() * has had a chance to interoogate it. */ free(controller->devices[devno]); diff --git a/payloads/libpayload/drivers/usb/usb_dev.c b/payloads/libpayload/drivers/usb/usb_dev.c index 9a0aecda7b..e67f6e3d7a 100644 --- a/payloads/libpayload/drivers/usb/usb_dev.c +++ b/payloads/libpayload/drivers/usb/usb_dev.c @@ -32,8 +32,6 @@ static void usb_nop_destroy (usbdev_t *dev) { - if (dev->descriptor != 0) - free (dev->descriptor); usb_nop_init (dev); dev->address = -1; dev->hub = -1; @@ -49,7 +47,8 @@ usb_nop_poll (usbdev_t *dev) void usb_nop_init (usbdev_t *dev) { - dev->descriptor = 0; + dev->descriptor = NULL; + dev->configuration = NULL; dev->destroy = usb_nop_destroy; dev->poll = usb_nop_poll; } diff --git a/payloads/libpayload/drivers/usb/usbhid.c b/payloads/libpayload/drivers/usb/usbhid.c index 67aebb2ffd..22ed8e7885 100644 --- a/payloads/libpayload/drivers/usb/usbhid.c +++ b/payloads/libpayload/drivers/usb/usbhid.c @@ -80,6 +80,9 @@ usb_hid_destroy (usbdev_t *dev) &dev->endpoints[i], HID_INST(dev)->queue); HID_INST(dev)->queue = NULL; } + free(HID_INST(dev)->descriptor); + HID_INST(dev)->descriptor = NULL; + free (dev->data); } -- cgit v1.2.3