From 074c8ceb1d565d0cd90ed197d1fdb5e78f767101 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 3 Apr 2024 14:08:24 +0200 Subject: [PATCH] fix memory alloc issue --- src/battery.c | 1 - src/helper.c | 10 ++++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/battery.c b/src/battery.c index 2d731bb..1baa669 100644 --- a/src/battery.c +++ b/src/battery.c @@ -27,7 +27,6 @@ int get_battery_level(const char *device_path, bool *is_charging) { } unsigned char report[RAZER_REPORT_LEN] = {0}; - DWORD bytesReturned; // Prepare the report to request battery information report[0] = RAZER_REPORT_ID_BATTERY; diff --git a/src/helper.c b/src/helper.c index cc303ff..045d272 100644 --- a/src/helper.c +++ b/src/helper.c @@ -29,8 +29,14 @@ void find_device_path(int pid, char *device_path) { SetupDiGetDeviceInterfaceDetail(hDevInfo, &deviceInterfaceData, NULL, 0, &requiredSize, NULL); - PSP_DEVICE_INTERFACE_DETAIL_DATA detailData = - (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(requiredSize); + PSP_DEVICE_INTERFACE_DETAIL_DATA detailData; + 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); if (SetupDiGetDeviceInterfaceDetail(hDevInfo, &deviceInterfaceData,