summaryrefslogtreecommitdiff
path: root/libusb
diff options
context:
space:
mode:
authorPete Batard <pbatard@gmail.com>2010-11-13 01:39:04 +0000
committerPete Batard <pbatard@gmail.com>2010-11-13 01:39:04 +0000
commit8cc6b97f1dc46413263d2de11cecffed972d5be3 (patch)
tree5592320074e62ae97aa1c49cdd95ab19d3a72740 /libusb
parentd95400144bfd1c8a6eeaf745070592e2c9ad3b08 (diff)
downloadlibusb-8cc6b97f1dc46413263d2de11cecffed972d5be3.tar.gz
use _close() rather than CloseHandle() in usbi_close()
* use of CloseHandle() prevented the pipe fds from being relinquished on libusb_exit() * leaked fds could lead to the OS running out of new fds and LIBUSB_ERROR_NO_MEM being returned as a result * issue reported by Stephano Antonelli
Diffstat (limited to 'libusb')
-rw-r--r--libusb/os/poll_windows.c8
-rw-r--r--libusb/os/poll_windows.h8
2 files changed, 8 insertions, 8 deletions
diff --git a/libusb/os/poll_windows.c b/libusb/os/poll_windows.c
index 3657be5..f7ca6ea 100644
--- a/libusb/os/poll_windows.c
+++ b/libusb/os/poll_windows.c
@@ -401,7 +401,8 @@ struct winfd usbi_create_fd(HANDLE handle, int access_mode)
wfd.rw = RW_WRITE;
}
- // Ensure that we get a non system conflicting unique fd
+ // Ensure that we get a non system conflicting unique fd, using
+ // the same fd attribution system as the pipe ends
fd = _open_osfhandle((intptr_t)CreateFileA("NUL", 0, 0,
NULL, OPEN_EXISTING, 0, NULL), _O_RDWR);
if (fd < 0) {
@@ -788,10 +789,9 @@ int usbi_close(int fd)
CloseHandle(poll_fd[_index].overlapped->hEvent);
free(poll_fd[_index].overlapped);
}
- if (CloseHandle(poll_fd[_index].handle) == 0) {
+ r = _close(poll_fd[_index].fd);
+ if (r != 0) {
errno = EIO;
- } else {
- r = 0;
}
poll_fd[_index] = INVALID_WINFD;
LeaveCriticalSection(&_poll_fd[_index].mutex);
diff --git a/libusb/os/poll_windows.h b/libusb/os/poll_windows.h
index a9e3e90..dfa4650 100644
--- a/libusb/os/poll_windows.h
+++ b/libusb/os/poll_windows.h
@@ -72,10 +72,10 @@ enum rw_type {
// fd struct that can be used for polling on Windows
struct winfd {
- int fd; // what's exposed to libusb core
- HANDLE handle; // what we need to attach overlapped to the I/O op, so we can poll it
- OVERLAPPED* overlapped; // what will report our I/O status
- enum rw_type rw; // I/O transfer direction: read *XOR* write (NOT BOTH)
+ int fd; // what's exposed to libusb core
+ HANDLE handle; // what we need to attach overlapped to the I/O op, so we can poll it
+ OVERLAPPED* overlapped; // what will report our I/O status
+ enum rw_type rw; // I/O transfer direction: read *XOR* write (NOT BOTH)
};
extern const struct winfd INVALID_WINFD;