mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usbutils.git
synced 2024-11-26 21:33:41 +08:00
lsusb-t: fix memory leak
The lists were never being cleaned up when finished, so properly walk them and free the allocated the memory that was allocated. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
d04e63e551
commit
a68705def3
23
lsusb-t.c
23
lsusb-t.c
@ -717,6 +717,28 @@ static void print_tree(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void cleanup(void)
|
||||
{
|
||||
struct usbdevice *device, *tempd;
|
||||
struct usbinterface *interface, *templ;
|
||||
struct usbbusnode *bus, *tempb;
|
||||
|
||||
list_for_each_safe(&usbdevlist, device, tempd, list) {
|
||||
free(device);
|
||||
}
|
||||
|
||||
list_for_each_safe(&interfacelist, interface, templ, list) {
|
||||
free(interface);
|
||||
}
|
||||
|
||||
bus = usbbuslist;
|
||||
while (bus) {
|
||||
tempb = bus->next;
|
||||
free(bus);
|
||||
bus = tempb;
|
||||
}
|
||||
}
|
||||
|
||||
int lsusb_t(void)
|
||||
{
|
||||
DIR *sbud = opendir(sys_bus_usb_devices);
|
||||
@ -727,6 +749,7 @@ int lsusb_t(void)
|
||||
sort_devices();
|
||||
sort_busses();
|
||||
print_tree();
|
||||
cleanup();
|
||||
} else
|
||||
perror(sys_bus_usb_devices);
|
||||
return sbud == NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user