From 16f1ec0b48a6ebb74ef79491fbbcefdce2712d10 Mon Sep 17 00:00:00 2001 From: Callum Bryant Date: Fri, 21 Jul 2023 11:06:08 +1000 Subject: [PATCH] fix memory leak --- src/DesktopMonitorBrightness.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/DesktopMonitorBrightness.cpp b/src/DesktopMonitorBrightness.cpp index 57323e9..f73bc00 100644 --- a/src/DesktopMonitorBrightness.cpp +++ b/src/DesktopMonitorBrightness.cpp @@ -181,6 +181,12 @@ BOOL CALLBACK DesktopMonitorManager::MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< this is causing exceptions!!! } } + + // Clean up allocated memory + if (pPhysicalMonitors != NULL) { + free(pPhysicalMonitors); // Deallocate the memory + pPhysicalMonitors = NULL; // Set the pointer to NULL to avoid using it again. + } // we always return true to signal that we want to keep looking return true; @@ -476,4 +482,4 @@ BOOL CALLBACK DesktopMonitorManager::MonitorEnum(HMONITOR hMon, HDC hdc, LPRECT error = buff.str(); return return_value; - } \ No newline at end of file + }