Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/23689
Change subject: libpayload/drivers/usb: Fix leaks ......................................................................
libpayload/drivers/usb: Fix leaks
Don't leak buffers on device detach.
Tested on Lenovo T500 using UHCI controller by attaching and detaching USB devices a few hundred times.
Change-Id: Ib2d80dd4590aa0dacdf2da3b614c6505c931d0be Signed-off-by: Patrick Rudolph siro@das-labor.org --- M payloads/libpayload/drivers/usb/usb.c M payloads/libpayload/drivers/usb/usb_dev.c M payloads/libpayload/drivers/usb/usbhid.c M payloads/libpayload/drivers/usb/usbmsc.c 4 files changed, 26 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/89/23689/1
diff --git a/payloads/libpayload/drivers/usb/usb.c b/payloads/libpayload/drivers/usb/usb.c index 906df84..5d36585 100644 --- a/payloads/libpayload/drivers/usb/usb.c +++ b/payloads/libpayload/drivers/usb/usb.c @@ -669,6 +669,13 @@ { if (usb_generic_remove) usb_generic_remove(dev); + + if (dev->descriptor) + free(dev->descriptor); + dev->descriptor = 0; + if (dev->configuration) + free(dev->configuration); + dev->configuration = 0; }
void diff --git a/payloads/libpayload/drivers/usb/usb_dev.c b/payloads/libpayload/drivers/usb/usb_dev.c index 9a0aecd..096c072 100644 --- a/payloads/libpayload/drivers/usb/usb_dev.c +++ b/payloads/libpayload/drivers/usb/usb_dev.c @@ -34,6 +34,8 @@ { if (dev->descriptor != 0) free (dev->descriptor); + if (dev->configuration != 0) + free(dev->configuration); usb_nop_init (dev); dev->address = -1; dev->hub = -1; @@ -50,6 +52,7 @@ usb_nop_init (usbdev_t *dev) { dev->descriptor = 0; + dev->configuration = 0; 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 3100d37..08dae24 100644 --- a/payloads/libpayload/drivers/usb/usbhid.c +++ b/payloads/libpayload/drivers/usb/usbhid.c @@ -80,7 +80,17 @@ &dev->endpoints[i], HID_INST(dev)->queue); HID_INST(dev)->queue = NULL; } + if (HID_INST(dev)->descriptor) + free(HID_INST(dev)->descriptor); + HID_INST(dev)->descriptor = 0; + free (dev->data); + if (dev->descriptor) + free(dev->descriptor); + dev->descriptor = 0; + if (dev->configuration) + free(dev->configuration); + dev->configuration = 0; }
/* keybuffer is global to all USB keyboards */ diff --git a/payloads/libpayload/drivers/usb/usbmsc.c b/payloads/libpayload/drivers/usb/usbmsc.c index 2c7cbe5..866d23d 100644 --- a/payloads/libpayload/drivers/usb/usbmsc.c +++ b/payloads/libpayload/drivers/usb/usbmsc.c @@ -91,6 +91,12 @@ free (dev->data); } dev->data = 0; + if (dev->descriptor) + free(dev->descriptor); + dev->descriptor = 0; + if (dev->configuration) + free(dev->configuration); + dev->configuration = 0; }
const int DEV_RESET = 0xff;