diff options
author | Michael Plante <michael.plante@gmail.com> | 2010-02-11 17:11:15 -0600 |
---|---|---|
committer | Pete Batard <pbatard@gmail.com> | 2010-02-12 00:06:50 +0000 |
commit | 8c605c7779b774fbbf3aaa5159882712290d86fe (patch) | |
tree | 76f91e5678ed667341b0223282b13c274ce548b7 /libusb | |
parent | 1cda5082f89d3e8a10fb35bdba74440241d7d822 (diff) | |
download | libusb-8c605c7779b774fbbf3aaa5159882712290d86fe.tar.gz |
fix 2 timer-related bugs (unlikely)r151
* failed to check CreateSemaphore()
* index out of bounds on timer_index
Diffstat (limited to 'libusb')
-rw-r--r-- | libusb/os/windows_usb.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index a16b140..a3b2969 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -449,7 +449,7 @@ static int windows_init(struct libusb_context *ctx) if (i==2) break; // 3rd event has no matching parts, because it's for quitting the thread. timer_response[i] = CreateSemaphore(NULL, 0, MAX_TIMER_SEMAPHORES, NULL); - if (timer_request[i] == NULL) { + if (timer_response[i] == NULL) { usbi_err(ctx, "could not create timer response semaphore %d - aborting", i); goto init_exit; } @@ -1921,6 +1921,10 @@ unsigned __stdcall windows_clock_gettime_threaded(void* param) } while (1) { timer_index = WaitForMultipleObjects(3, timer_request, FALSE, INFINITE) - WAIT_OBJECT_0; + if (timer_index < 0 || timer_index > 2) { + usbi_dbg("failure to wait on requests: %s", windows_error_str(0)); + continue; + } if (request_count[timer_index] == 0) { // Request already handled ResetEvent(timer_request[timer_index]); @@ -1961,9 +1965,6 @@ unsigned __stdcall windows_clock_gettime_threaded(void* param) case 2: // time to quit usbi_dbg("timer thread quitting"); return 0; - default: - usbi_dbg("failure to wait on requests: %s", windows_error_str(0)); - continue; send_response: nb_responses = InterlockedExchange((LONG*)&request_count[i], 0); if ( (nb_responses) |