mik3y / usb-serial-for-android

Android USB host serial driver library for CDC, FTDI, Arduino and other devices.
MIT License
4.82k stars 1.58k forks source link

Leak in CommonUsbSerialPort close method assumed by Android StrictMode class #460

Closed tom42530 closed 1 year ago

tom42530 commented 1 year ago

Hi,

first thanks for your amazing work.

Seen with strict mode enable aka : StrictMode.enableDefaults(); Ressource mUsbRequest is never closed close method only cancel and set it to null but never call close to release associated ressource. To fix it simply call mUsbRequest.close l.143

Thanks in advance

kai-morich commented 1 year ago

UsbRequest.finalize closes the UsbRequest. With cancel a SerialInputOutputManager thread that is blocking in read serial port is woken up. Have to test what happens if the UsbRequest is closed before

kai-morich commented 1 year ago

I couldnt reproduce the StrictMode output, only got other unrelated StrictMode output. Closing the usbRequest earlier causes strange NullPointer Exceptions inside Android USB functions. As the object is closed by the finalizer, I keep as is.