fix memory alloc issue
This commit is contained in:
parent
189e148829
commit
074c8ceb1d
2 changed files with 8 additions and 3 deletions
|
@ -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;
|
||||||
|
|
10
src/helper.c
10
src/helper.c
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue