[argyllcms] Memory leak in usbio.c

  • From: Ian <pb23@xxxxxxxxxxxxx>
  • To: argyllcms@xxxxxxxxxxxxx
  • Date: Sat, 14 Apr 2012 04:32:10 +0100

usb_get_paths() has a memory leak. Taking the address of libusb_context *ctx in the manner below will yield a non-null value when passing it to libusb_init(&ctx). This causes libusb_init() to allocate a new non-default context. The allocated context is not deleted when the function usb_get_paths() terminates, resulting in a memory leak.

// Ian

void usb_get_paths(
struct _icoms *p
) {
    ssize_t i, nlist;
    libusb_context *ctx = NULL;

    struct libusb_device **list;

    /* Scan the USB busses for instruments we recognise */
/* We're not expecting any of our unstruments to be an interface on a device. */


    if (p->debug > 8)
        libusb_set_debug(ctx, p->debug);

    nlist = libusb_get_device_list(NULL, &list);

if (p->debug) fprintf(stderr,"usb_get_paths about to look through devices:\n");

    for (i = 0; i < nlist; i++) {
        usb_check_and_add(p, list[i]);

    libusb_free_device_list(list,  1);
#endif /* ENABLE_USB */

Other related posts:

  • » [argyllcms] Memory leak in usbio.c - Ian