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 + }