From 57f104f051f2dc6eefc2f3e989f6e20a7227908e Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 27 Sep 2024 14:59:17 +0200 Subject: [PATCH] libusb: Add missing checks after new_hid_device --- libusb/hid.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libusb/hid.c b/libusb/hid.c index fbb10d16..a5384e14 100644 --- a/libusb/hid.c +++ b/libusb/hid.c @@ -1310,6 +1310,10 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path) return NULL; dev = new_hid_device(); + if (!dev) { + LOG("hid_open_path failed: Couldn't allocate memory\n"); + return NULL; + } libusb_get_device_list(usb_context, &devs); while ((usb_dev = devs[d++]) != NULL && !good_open) { @@ -1381,6 +1385,10 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_libusb_wrap_sys_device(intptr_t sys return NULL; dev = new_hid_device(); + if (!dev) { + LOG("libusb_wrap_sys_device failed: Couldn't allocate memory\n"); + return NULL; + } res = libusb_wrap_sys_device(usb_context, sys_dev, &dev->device_handle); if (res < 0) {