From 0abd328718325bbeef46bf9dd3079aed45ead5ee Mon Sep 17 00:00:00 2001 From: Megamouse Date: Wed, 26 Jan 2022 20:41:02 +0100 Subject: [PATCH] hid_open_path: Don't pass invalid pointers to HidD_FreePreparsedData Fixes a segfault that happens when hid_open_path is called on a previously disconnected device. This is a regression caused by: b600727 - Win32: Fix memory leak in `free_hid_device` (#361) --- windows/hid.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/windows/hid.c b/windows/hid.c index 6d93047..96b0b82 100644 --- a/windows/hid.c +++ b/windows/hid.c @@ -862,7 +862,10 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path) end_of_function: CloseHandle(device_handle); - HidD_FreePreparsedData(pp_data); + + if (pp_data) { + HidD_FreePreparsedData(pp_data); + } return dev; }