summaryrefslogtreecommitdiff
path: root/libusb
diff options
context:
space:
mode:
authorPete Batard <pbatard@gmail.com>2010-10-12 23:10:26 +0100
committerPete Batard <pbatard@gmail.com>2010-10-12 23:10:26 +0100
commit5c7ef20119c427e7ef99990ed270fc4fa5d9698f (patch)
treeab0735c342a7c8e0509fbf76d255f5c1e7a558f3 /libusb
parentc7a064548d3672e4e47430bfd739854fe5cc3774 (diff)
downloadlibusb-5c7ef20119c427e7ef99990ed270fc4fa5d9698f.tar.gz
fixed missing malloc check in htab_hash()pbr312
* spotted by Michael Plante * also some cleanup
Diffstat (limited to 'libusb')
-rw-r--r--libusb/libusb_version.h2
-rw-r--r--libusb/os/windows_usb.c10
2 files changed, 6 insertions, 6 deletions
diff --git a/libusb/libusb_version.h b/libusb/libusb_version.h
index f5db4b8..b3bee2b 100644
--- a/libusb/libusb_version.h
+++ b/libusb/libusb_version.h
@@ -24,6 +24,6 @@
#define LIBUSB_VERSION_MAJOR 1
#define LIBUSB_VERSION_MINOR 0
#define LIBUSB_VERSION_MICRO 8
-#define LIBUSB_VERSION_NANO 10311
+#define LIBUSB_VERSION_NANO 10312
#endif
diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c
index 5281e31..8842ebf 100644
--- a/libusb/os/windows_usb.c
+++ b/libusb/os/windows_usb.c
@@ -462,7 +462,6 @@ void htab_destroy(void)
}
/* This is the search function. It uses double hashing with open addressing.
-
We use an trick to speed up the lookup. The table is created with one
more element available. This enables us to use the index zero special.
This index will never be used because we store the first hash index in
@@ -470,10 +469,6 @@ void htab_destroy(void)
The used field can be used as a first fast comparison for equality of
the stored and the parameter value. This helps to prevent unnecessary
expensive calls of strcmp. */
-
-/* NB: the only way we would ever need a mutex here is if 2 colliding
- hashes were to be stored concurrently from 2 different threads. */
-
unsigned long htab_hash(char* str)
{
unsigned long hval, hval2;
@@ -546,6 +541,11 @@ unsigned long htab_hash(char* str)
safe_free(htab_table[idx].str);
htab_table[idx].used = hval;
htab_table[idx].str = malloc(safe_strlen(str)+1);
+ if (htab_table[idx].str == NULL) {
+ usbi_err(NULL, "could not duplicate string for hash table");
+ usbi_mutex_unlock(&htab_write_mutex);
+ return 0;
+ }
memcpy(htab_table[idx].str, str, safe_strlen(str)+1);
++htab_filled;
usbi_mutex_unlock(&htab_write_mutex);