From adf0581b88e883c733905c89bfd562f0decc0ca4 Mon Sep 17 00:00:00 2001 From: Christian Ferbar Date: Tue, 27 Mar 2018 20:34:39 +0200 Subject: add: cleanup on error --- src/k8055.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/k8055.c b/src/k8055.c index 6f3bc17..6b10cca 100644 --- a/src/k8055.c +++ b/src/k8055.c @@ -181,6 +181,8 @@ int k8055_open_device(int port, k8055_device** device) { ssize_t size = libusb_get_device_list(context, &connected_devices); /* get all devices on system */ if (size <= 0) { print_error("no usb devices found on system"); + if (k8055_open_devices <= 0) + libusb_exit(context); return K8055_ERROR_NO_DEVICES; } @@ -195,6 +197,9 @@ int k8055_open_device(int port, k8055_device** device) { } if (k8055 == NULL) { print_error("velleman k8055 not found at port"); + libusb_free_device_list(connected_devices, 1); // cleanup + if (k8055_open_devices <= 0) + libusb_exit(context); return K8055_ERROR_NO_K8055; } -- cgit v1.2.3