fix memory alloc issue

This commit is contained in:
Mylloon 2024-04-03 14:08:24 +02:00
parent 189e148829
commit 074c8ceb1d
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 8 additions and 3 deletions

View file

@ -27,7 +27,6 @@ int get_battery_level(const char *device_path, bool *is_charging) {
} }
unsigned char report[RAZER_REPORT_LEN] = {0}; unsigned char report[RAZER_REPORT_LEN] = {0};
DWORD bytesReturned;
// Prepare the report to request battery information // Prepare the report to request battery information
report[0] = RAZER_REPORT_ID_BATTERY; report[0] = RAZER_REPORT_ID_BATTERY;

View file

@ -29,8 +29,14 @@ void find_device_path(int pid, char *device_path) {
SetupDiGetDeviceInterfaceDetail(hDevInfo, &deviceInterfaceData, NULL, 0, SetupDiGetDeviceInterfaceDetail(hDevInfo, &deviceInterfaceData, NULL, 0,
&requiredSize, NULL); &requiredSize, NULL);
PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = PSP_DEVICE_INTERFACE_DETAIL_DATA detailData;
(PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(requiredSize); if (!(detailData =
(PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(requiredSize))) {
fprintf_s(
stderr,
"Failed to allocated memory for PSP_DEVICE_INTERFACE_DETAIL_DATA.\n");
return;
}
detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); detailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
if (SetupDiGetDeviceInterfaceDetail(hDevInfo, &deviceInterfaceData, if (SetupDiGetDeviceInterfaceDetail(hDevInfo, &deviceInterfaceData,