the past, I thought it would be a good idea to move this to hid_close(), but
I can't now understand why, as freeing these objects in read_thread() makes
sense because they are created in read_thread().
This code never made it into hid_close(), so it's now re-activated in
read_thread().
Reported-by: Ludovic Rousseau <ludovic.rousseau@gmail.com>
hid_close() would hang on pthread_join() if hid_close() was called while the
reading thread was executing read_callback() _before_ the call to
libusb_submit_transfer(). This caused libusb_cancel_transfer() to fail, and
the read thread would never stop (and hid_close() would never return).
This patch simply sets the shutdown_thread flag from read_close(). This way,
even if hid_close() is called while there is no transfer pending, the loop
in read_thread() will exit, causing read_thread() to end. For this to not
leak resources, read_thread() also now has to call libusb_cancel_transfer().
Note that necessarily, one of the calls to libusb_submit_transfer() will
fail (and return an error code), but that's ok, because one of them is
guaranteed to succeed.
Reported-by: Ludovic Rousseau <ludovic.rousseau@gmail.com>
has been initialized before hid_open_path() returns. There was a race
condition if hid_close() was called immediately after hid_open(), because
hid_close() was trying to destroy objects that read_thread() had sometimes
not created yet.
Reported-by: Ludovic Rousseau <rousseau@debian.org>
iconv_open() returns a iconv_t so is always a positive value.
In case of error the returned value is (iconv_t)-1 so compare with this
specific value instead of < 0
Signed-off-by: Alan Ott <alan@signal11.us>
iconv() returns a size_t so is always a positive value.
In case of error the returned value is (size_t)-1 so compare with this
specific value instead of < 0
Signed-off-by: Alan Ott <alan@signal11.us>
hid-libusb.c:172: warning: declaration of ‘index’ shadows a global declaration
/usr/include/string.h:487: warning: shadowed declaration is here
Use idx instead of index to avoid collision with index()
Signed-off-by: Alan Ott <alan@signal11.us>
hid-libusb.c:223: warning: array subscript is above array bounds
sizeof(wbuf) gives the size of the wbuf array in char. It is also the
number of element only if wbuf is an array of char.
Here wbuf is an array of wchar_t so the last element of the array is
wbuf[sizeof(wbuf)/sizeof(wbuf[0])-1]
Signed-off-by: Alan Ott <alan@signal11.us>
Functions with no arguments should use void
hid-libusb.c:93: warning: function declaration isn’t a prototype
hid-libusb.c:97: warning: function declaration isn’t a prototype
hid-libusb.c:1010: warning: function declaration isn’t a prototype
Signed-off-by: Alan Ott <alan@signal11.us>