machinekit-hal icon indicating copy to clipboard operation
machinekit-hal copied to clipboard

xhc-hb04: Memleak - libusb_alloc_transfer(0)

Open ArcEye opened this issue 7 years ago • 3 comments

Issue by rubienr Sun Aug 27 15:46:18 2017 Originally opened as https://github.com/machinekit/machinekit/issues/1255


  • Reason:

Any libusb_transfer struct is requested from libusb but never released gracefully.

  • Where:

xhc-hb04.cc:L443

void setup_asynch_transfer(libusb_device_handle *dev_handle)
442	{
443		transfer_in  = libusb_alloc_transfer(0);
444		libusb_fill_bulk_transfer( transfer_in, dev_handle, (0x1 | LIBUSB_ENDPOINT_IN),
445			in_buf, sizeof(in_buf),
446			cb_response_in, NULL, 0); // no user data
447		libusb_submit_transfer(transfer_in);
448	}
  • HotFix:
void setup_asynch_transfer(libusb_device_handle *dev_handle)
442	{
                if (transfer_in != nullptr) 
                {
   			libusb_free_transfer(transfer_in);
   			transfer_in = nullptr;
                }
443		transfer_in  = libusb_alloc_transfer(0);
444		libusb_fill_bulk_transfer( transfer_in, dev_handle, (0x1 | LIBUSB_ENDPOINT_IN),
445			in_buf, sizeof(in_buf),
446			cb_response_in, NULL, 0); // no user data
447		libusb_submit_transfer(transfer_in);
448	}

ArcEye avatar Aug 03 '18 15:08 ArcEye

Comment by ArcEye Sun Aug 27 16:01:32 2017


Could you submit a PR please. You may want to do the same to linuxcnc, the code comes directly from there.

ArcEye avatar Aug 03 '18 15:08 ArcEye

Comment by rubienr Sun Aug 27 16:09:40 2017


Do you wish having one PR per issue or one PR combining all xhc-hb04 issues?

ArcEye avatar Aug 03 '18 15:08 ArcEye

Comment by ArcEye Sun Aug 27 16:22:08 2017


A single PR addressing both issues is fine thanks

ArcEye avatar Aug 03 '18 15:08 ArcEye