diff --git a/Source/Core/Core/HW/WiimoteReal/IOWin.cpp b/Source/Core/Core/HW/WiimoteReal/IOWin.cpp index f755eedb6b..74cfe5cb88 100644 --- a/Source/Core/Core/HW/WiimoteReal/IOWin.cpp +++ b/Source/Core/Core/HW/WiimoteReal/IOWin.cpp @@ -418,6 +418,10 @@ int WriteToHandle(HANDLE& dev_handle, WinWriteMethod& method, const u8* buf, siz { OVERLAPPED hid_overlap_write = OVERLAPPED(); hid_overlap_write.hEvent = CreateEvent(nullptr, true, false, nullptr); + if (!hid_overlap_write.hEvent) + { + return 0; + } DWORD written = 0; IOWrite(dev_handle, hid_overlap_write, method, buf, size, &written); @@ -431,6 +435,10 @@ int ReadFromHandle(HANDLE& dev_handle, u8* buf) { OVERLAPPED hid_overlap_read = OVERLAPPED(); hid_overlap_read.hEvent = CreateEvent(nullptr, true, false, nullptr); + if (!hid_overlap_read.hEvent) + { + return 0; + } const int read = IORead(dev_handle, hid_overlap_read, buf, 1); CloseHandle(hid_overlap_read.hEvent); return read; @@ -533,7 +541,6 @@ void WiimoteScannerWindows::FindWiimotes(std::vector& found_wiimotes, SP_DEVICE_INTERFACE_DATA device_data = {}; device_data.cbSize = sizeof(device_data); - PSP_DEVICE_INTERFACE_DETAIL_DATA detail_data = nullptr; for (int index = 0; SetupDiEnumDeviceInterfaces(device_info, nullptr, &device_id, index, &device_data); ++index) @@ -541,7 +548,8 @@ void WiimoteScannerWindows::FindWiimotes(std::vector& found_wiimotes, // Get the size of the data block required DWORD len; SetupDiGetDeviceInterfaceDetail(device_info, &device_data, nullptr, 0, &len, nullptr); - detail_data = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(len); + auto detail_data_buf = std::make_unique(len); + auto detail_data = reinterpret_cast(detail_data_buf.get()); detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); SP_DEVINFO_DATA device_info_data = {}; @@ -558,7 +566,6 @@ void WiimoteScannerWindows::FindWiimotes(std::vector& found_wiimotes, if (!IsNewWiimote(WStringToUTF8(device_path)) || !IsWiimote(device_path, write_method)) { - free(detail_data); continue; } @@ -568,8 +575,6 @@ void WiimoteScannerWindows::FindWiimotes(std::vector& found_wiimotes, else found_wiimotes.push_back(wiimote); } - - free(detail_data); } SetupDiDestroyDeviceInfoList(device_info);