summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Dickens <christopher.a.dickens@gmail.com>2016-05-29 19:44:29 -0700
committerChris Dickens <christopher.a.dickens@gmail.com>2016-05-29 21:10:18 -0700
commit247c719cb8842a46662e8d62eb31cacc134aee51 (patch)
treeedd5203d878ec469b20a4c0e13e269b8718f01f7
parentadb6e39b68699b5d849836f9aaff7640b0f16173 (diff)
downloadlibusb-247c719cb8842a46662e8d62eb31cacc134aee51.tar.gz
Windows: Clean up referenced devices when memory allocation fails
Similar to commit adb6e39b68699b5d849836f9aaff7640b0f16173, drop the use of usbi_reallocf() as the memory would be freed, thereby leaking device references. Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r--libusb/os/windows_winusb.c16
-rw-r--r--libusb/version_nano.h2
2 files changed, 9 insertions, 9 deletions
diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c
index 80e36fb..50d4034 100644
--- a/libusb/os/windows_winusb.c
+++ b/libusb/os/windows_winusb.c
@@ -1305,7 +1305,7 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered
GUID *if_guid;
LONG s;
// Keep a list of newly allocated devs to unref
- libusb_device **unref_list;
+ libusb_device **unref_list, **new_unref_list;
unsigned int unref_size = 64;
unsigned int unref_cur = 0;
@@ -1535,10 +1535,12 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered
unref_list[unref_cur++] = dev;
if (unref_cur >= unref_size) {
unref_size += 64;
- unref_list = usbi_reallocf(unref_list, unref_size * sizeof(libusb_device *));
- if (unref_list == NULL) {
+ new_unref_list = usbi_reallocf(unref_list, unref_size * sizeof(libusb_device *));
+ if (new_unref_list == NULL) {
usbi_err(ctx, "could not realloc list for unref - aborting.");
LOOP_BREAK(LIBUSB_ERROR_NO_MEM);
+ } else {
+ unref_list = new_unref_list;
}
}
}
@@ -1640,11 +1642,9 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered
safe_free(guid[pass]);
// Unref newly allocated devs
- if (unref_list != NULL) {
- for (i = 0; i < unref_cur; i++)
- safe_unref_device(unref_list[i]);
- free(unref_list);
- }
+ for (i = 0; i < unref_cur; i++)
+ safe_unref_device(unref_list[i]);
+ free(unref_list);
return r;
}
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 9e02ae0..9e268cd 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 11113
+#define LIBUSB_NANO 11114