diff options
author | Chris Dickens <christopher.a.dickens@gmail.com> | 2016-01-27 01:25:49 -0800 |
---|---|---|
committer | Chris Dickens <christopher.a.dickens@gmail.com> | 2016-01-27 01:25:49 -0800 |
commit | d73aafe5c12d8ab41553daece8f3131107a2d62f (patch) | |
tree | f10fd76dc892268b1be748627d8c88491a469e1a | |
parent | fc721ede3e901fd8f25d2cc904a924384cd23d5f (diff) | |
download | libusb-d73aafe5c12d8ab41553daece8f3131107a2d62f.tar.gz |
Windows: Minor improvements to windows_nt_common.c
1) Possible memory leak is avoided if htab_create() is called
while a hash table is already allocated
2) Error handling is simplified in windows_handle_events()
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r-- | libusb/os/windows_nt_common.c | 8 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
2 files changed, 6 insertions, 4 deletions
diff --git a/libusb/os/windows_nt_common.c b/libusb/os/windows_nt_common.c index 9a4f854..30796ac 100644 --- a/libusb/os/windows_nt_common.c +++ b/libusb/os/windows_nt_common.c @@ -150,6 +150,7 @@ static bool htab_create(struct libusb_context *ctx, unsigned long nel) { if (htab_table != NULL) { usbi_err(ctx, "hash table already allocated"); + return true; } // Create a mutex @@ -537,6 +538,7 @@ int windows_handle_events(struct libusb_context *ctx, struct pollfd *fds, POLL_N struct usbi_transfer *transfer; struct winfd *pollable_fd = NULL; DWORD io_size, io_result; + int r = LIBUSB_SUCCESS; usbi_mutex_lock(&ctx->open_devs_lock); for (i = 0; i < nfds && num_ready > 0; i++) { @@ -570,14 +572,14 @@ int windows_handle_events(struct libusb_context *ctx, struct pollfd *fds, POLL_N // newly allocated wfd that took the place of the one from the transfer. windows_handle_callback(transfer, io_result, io_size); } else { - usbi_mutex_unlock(&ctx->open_devs_lock); usbi_err(ctx, "could not find a matching transfer for fd %d", fds[i]); - return LIBUSB_ERROR_NOT_FOUND; + r = LIBUSB_ERROR_NOT_FOUND; + break; } } usbi_mutex_unlock(&ctx->open_devs_lock); - return LIBUSB_SUCCESS; + return r; } int windows_common_init(struct libusb_context *ctx) diff --git a/libusb/version_nano.h b/libusb/version_nano.h index ca4d099..105925c 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11038 +#define LIBUSB_NANO 11039 |