mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
wiimotereal: add some error handling. replace malloc with make_unique
This commit is contained in:
parent
938fd4e438
commit
3ee4c53d65
@ -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<Wiimote*>& 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<Wiimote*>& 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<u8[]>(len);
|
||||
auto detail_data = reinterpret_cast<PSP_DEVICE_INTERFACE_DETAIL_DATA>(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<Wiimote*>& 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<Wiimote*>& found_wiimotes,
|
||||
else
|
||||
found_wiimotes.push_back(wiimote);
|
||||
}
|
||||
|
||||
free(detail_data);
|
||||
}
|
||||
|
||||
SetupDiDestroyDeviceInfoList(device_info);
|
||||
|
Loading…
Reference in New Issue
Block a user