From 7469f53c0d114c7bd69f5ad960bc0b57fc1953b7 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Wed, 8 Jul 2020 10:26:34 +0200 Subject: [PATCH] Added return checks for HashTable_Add (cherry picked from commit ea8f93441d523e103746dfeceab98420c05e0bac) --- channels/urbdrc/client/libusb/libusb_udevice.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/channels/urbdrc/client/libusb/libusb_udevice.c b/channels/urbdrc/client/libusb/libusb_udevice.c index c863925..a430ec4 100644 --- a/channels/urbdrc/client/libusb/libusb_udevice.c +++ b/channels/urbdrc/client/libusb/libusb_udevice.c @@ -1172,7 +1172,16 @@ static int libusb_udev_isoch_transfer(IUDEVICE* idev, URBDRC_CHANNEL_CALLBACK* c #endif libusb_set_iso_packet_lengths(iso_transfer, iso_packet_size); - HashTable_Add(pdev->request_queue, (void*)(size_t)streamID, iso_transfer); + if ((HashTable_Contains(pdev->request_queue, (void*)(size_t)streamID)) || + (HashTable_Add(pdev->request_queue, (void*)(size_t)streamID, iso_transfer) < 0)) + { + WLog_Print(urbdrc->log, WLOG_WARN, + "Failed to queue iso transfer, streamID %08" PRIx32 " already in use!", + streamID); + async_transfer_user_data_free(user_data); + libusb_free_transfer(iso_transfer); + return -1; + } return libusb_submit_transfer(iso_transfer); } @@ -1282,7 +1291,15 @@ static int libusb_udev_bulk_or_interrupt_transfer(IUDEVICE* idev, URBDRC_CHANNEL #else user_data->streamID = streamID; #endif - HashTable_Add(pdev->request_queue, (void*)(size_t)streamID, transfer); + if ((HashTable_Contains(pdev->request_queue, (void*)(size_t)streamID)) || + (HashTable_Add(pdev->request_queue, (void*)(size_t)streamID, transfer) < 0)) + { + WLog_Print(urbdrc->log, WLOG_WARN, + "Failed to queue transfer, streamID %08" PRIx32 " already in use!", streamID); + async_transfer_user_data_free(user_data); + libusb_free_transfer(transfer); + return -1; + } return libusb_submit_transfer(transfer); } -- 2.7.4