Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: pix/hidapi
base: 687a8385a1
...
head fork: pix/hidapi
compare: 1e1e48e523
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jul 19, 2011
@pix Fixed a leak where hid_open weren't freeing a device_path 110de52
@pix Added a hid_exit function do do cleanup some before exiting
  - Close device in hidtest.cpp
  - Call hid_exit() at the end

  - TODO: MacOS and Windows use a blank hid_exit

Signed-off-by: Camille Moncelier <moncelier@devlife.org>
4467a20
@pix Merge branches 'feature/hid_exit' and 'fixes/fix-hid_open-leak' 1e1e48e
View
11 hidapi/hidapi.h
@@ -77,6 +77,17 @@ extern "C" {
};
+ /** @brief Deinitialize hidapi
+
+ Deinitialize libusb.
+
+ This function should be called after closing all open devices
+ and before your application terminates.
+
+ @ingroup API
+ */
+ void HID_API_EXPORT HID_API_CALL hid_exit();
+
/** @brief Enumerate the HID Devices.
This function returns a linked list of all the HID devices
View
4 hidtest/hidtest.cpp
@@ -69,6 +69,7 @@ int main(int argc, char* argv[])
handle = hid_open(0x4d8, 0x3f, NULL);
if (!handle) {
printf("unable to open device\n");
+ hid_exit();
return 1;
}
@@ -182,5 +183,8 @@ int main(int argc, char* argv[])
system("pause");
#endif
+ hid_close(handle);
+ hid_exit();
+
return 0;
}
View
11 linux/hid-libusb.c
@@ -378,6 +378,14 @@ static char *make_path(libusb_device *dev, int interface_number)
return strdup(str);
}
+void HID_API_EXPORT hid_exit()
+{
+ if (initialized) {
+ libusb_exit(NULL);
+ initialized = 0;
+ }
+}
+
struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
libusb_device **devs;
@@ -752,6 +760,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
res = libusb_open(usb_dev, &dev->device_handle);
if (res < 0) {
LOG("can't open device\n");
+ free(dev_path);
break;
}
good_open = 1;
@@ -763,6 +772,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
if (res < 0) {
libusb_close(dev->device_handle);
LOG("Unable to detach Kernel Driver\n");
+ free(dev_path);
good_open = 0;
break;
}
@@ -771,6 +781,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
res = libusb_claim_interface(dev->device_handle, intf_desc->bInterfaceNumber);
if (res < 0) {
LOG("can't claim interface %d: %d\n", intf_desc->bInterfaceNumber, res);
+ free(dev_path);
libusb_close(dev->device_handle);
good_open = 0;
break;
View
4 linux/hid.c
@@ -193,6 +193,10 @@ static int get_device_string(hid_device *dev, const char *key, wchar_t *string,
return ret;
}
+void HID_API_EXPORT hid_exit()
+{
+ // Nothing to do (As far as i know)
+}
struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
View
4 mac/hid.c
@@ -288,6 +288,10 @@ static void init_hid_manager(void)
IOHIDManagerOpen(hid_mgr, kIOHIDOptionsTypeNone);
}
+void HID_API_EXPORT hid_exit()
+{
+ // TODO: Implement hid cleanup
+}
struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
View
7 windows/hid.cpp
@@ -184,6 +184,13 @@ static void lookup_functions()
}
#endif
+
+void HID_API_EXPORT hid_exit()
+{
+ // TODO: Keep an handle on hid.dll
+ // and call FreeLibrary(lib);
+}
+
struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id)
{
BOOL res;

No commit comments for this range

Something went wrong with that request. Please try again.