Package: bladerf / 0.2017.12~rc1-2

0012-Fix-mutex-handling-for-Windows-in-libusb-backend.-55.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From c297a11645f340b1d8b317a528c4239805de9632 Mon Sep 17 00:00:00 2001
From: Jean-Michel Picod <github@ichizoku.org>
Date: Wed, 28 Mar 2018 00:22:13 +0200
Subject: [PATCH 12/15] Fix mutex handling for Windows in libusb backend.
 (#550)

Calling ReleaseMutex without CloseHandle will let the mutex still exist until the process exists.
In such scenario, further calls to CreateMutex will succeed but GetLastError will return 183 (ERROR_ALREADY_EXISTS) causing libbladerf to fail opening the device. This can be assessed by running ```libbladeRF_test_open.exe -c 2 -v debug```.

Cypress backend is not affected as it systematically closes the handle after releasing the mutex.
---
 host/libraries/libbladeRF/src/backend/usb/libusb.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/host/libraries/libbladeRF/src/backend/usb/libusb.c b/host/libraries/libbladeRF/src/backend/usb/libusb.c
index ca447205..41cdaf8c 100644
--- a/host/libraries/libbladeRF/src/backend/usb/libusb.c
+++ b/host/libraries/libbladeRF/src/backend/usb/libusb.c
@@ -547,6 +547,7 @@ static int reset_and_reopen(libusb_context *context,
         libusb_close((*dev)->handle);
 #if 1 == BLADERF_OS_WINDOWS
         ReleaseMutex((*dev)->mutex);
+        CloseHandle((*dev)->mutex);
 #endif // BLADERF_OS_WINDOWS
 
         *dev = NULL;
@@ -651,6 +652,7 @@ static void lusb_close(void *driver)
     libusb_exit(lusb->context);
 #if 1 == BLADERF_OS_WINDOWS
     ReleaseMutex(lusb->mutex);
+    CloseHandle(lusb->mutex);
 #endif // BLADERF_OS_WINDOWS
     free(lusb);
 }
@@ -677,6 +679,7 @@ static void lusb_close_bootloader(void *driver)
 
 #if 1 == BLADERF_OS_WINDOWS
         ReleaseMutex(lusb->mutex);
+        CloseHandle(lusb->mutex);
 #endif // BLADERF_OS_WINDOWS
 
         free(lusb);
-- 
2.11.0