From 503dd1132ed2eac23f3dd9ee29f5db1ade45bef6 Mon Sep 17 00:00:00 2001 From: shakemid Date: Fri, 15 Sep 2017 20:44:33 +0900 Subject: [PATCH] Add cleanup function --- pcsensor.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pcsensor.c b/pcsensor.c index b2a4e35..7ffa037 100644 --- a/pcsensor.c +++ b/pcsensor.c @@ -280,6 +280,19 @@ void interrupt_read(libusb_device_handle *dev, unsigned char *answer) { } } +void cleanup_usb_devices(temper_device_t *devices, int numdev) { + int i; + + for (i = 0; i < numdev; i++) { + libusb_release_interface(devices[i].handle, INTERFACE1); + libusb_release_interface(devices[i].handle, INTERFACE2); + + libusb_close(devices[i].handle); + } + + libusb_exit(ctx); +} + void ex_program(int sig) { bsalir=1; @@ -452,14 +465,7 @@ int main(int argc, char **argv) { sleep(seconds); } while (!bsalir); - for (i = 0; i < numdev; i++) { - libusb_release_interface(devices[i].handle, INTERFACE1); - libusb_release_interface(devices[i].handle, INTERFACE2); - - libusb_close(devices[i].handle); - } - - libusb_exit(ctx); + cleanup_usb_devices(devices, numdev); return 0; }