Skip to content

Commit

Permalink
core: exit does not dereference device pointers when logging
Browse files Browse the repository at this point in the history
Device pointers that wrongly remain in the referenced device list could
point to already freed memory. Dereferencing them for the purpose of
logging devices related data could lead to segmentation faults
or inaccurate information
  • Loading branch information
sonatique committed Jan 24, 2024
1 parent 0929a2b commit e5e3b2b
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions libusb/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2626,11 +2626,8 @@ void API_EXPORTED libusb_exit(libusb_context *ctx)

usbi_io_exit(_ctx);

for_each_device(_ctx, dev) {
usbi_warn(_ctx, "device %d.%d still referenced",
dev->bus_number, dev->device_address);
DEVICE_CTX(dev) = NULL;
}
if (!list_empty(&_ctx->usb_devs))
usbi_warn(_ctx, "application left some devices referenced");

if (!list_empty(&_ctx->open_devs))
usbi_warn(_ctx, "application left some devices open");
Expand Down

0 comments on commit e5e3b2b

Please sign in to comment.