In hid_close() buffer pointer is freed and next to that the
libusb_free_transfer function is called which checks for if
the LIBUSB_TRANSFER_FREE_BUFFER flag is set and the buffer
pointer is not NULL. when this condition evaluates true, it
tries to free memory for a buffer which is already free and
a crash occurs.
Make buffer pointer NULL, once it is freed.
In hid_close() buffer pointer is freed and next to that the libusb_free_transfer function is called which checks for if the LIBUSB_TRANSFER_FREE_BUFFER flag is set and the buffer pointer is not NULL. when this condition evaluates true, it tries to free memory for a buffer which is already free and a crash occurs. Make buffer pointer NULL, once it is freed.