From 3c1bd7781334686b4d22b90334c0a44dba77b4dd Mon Sep 17 00:00:00 2001 From: jpirnay Date: Thu, 19 Feb 2026 12:13:12 +0100 Subject: [PATCH] fix: prevent UITheme memory leak on theme reload (#975) ## Summary - `UITheme::currentTheme` was a raw owning pointer with no destructor, causing a heap leak every time `setTheme()` was called (e.g. on theme change via settings reload) ## Additional Context - Replaced `const BaseTheme*` with `std::unique_ptr` so the previous theme object is automatically deleted on reassignment - Added `` include to `UITheme.h`; allocations updated to `std::make_unique<>` in `UITheme.cpp` --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**NO**_ (identified by claude though) --------- Co-authored-by: Dave Allie --- src/components/UITheme.cpp | 8 ++++---- src/components/UITheme.h | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/components/UITheme.cpp b/src/components/UITheme.cpp index 1779be3a..6555c09f 100644 --- a/src/components/UITheme.cpp +++ b/src/components/UITheme.cpp @@ -32,17 +32,17 @@ void UITheme::setTheme(CrossPointSettings::UI_THEME type) { switch (type) { case CrossPointSettings::UI_THEME::CLASSIC: LOG_DBG("UI", "Using Classic theme"); - currentTheme = new BaseTheme(); + currentTheme = std::make_unique(); currentMetrics = &BaseMetrics::values; break; case CrossPointSettings::UI_THEME::LYRA: LOG_DBG("UI", "Using Lyra theme"); - currentTheme = new LyraTheme(); + currentTheme = std::make_unique(); currentMetrics = &LyraMetrics::values; break; case CrossPointSettings::UI_THEME::LYRA_3_COVERS: LOG_DBG("UI", "Using Lyra 3 Covers theme"); - currentTheme = new Lyra3CoversTheme(); + currentTheme = std::make_unique(); currentMetrics = &Lyra3CoversMetrics::values; break; } @@ -89,4 +89,4 @@ UIIcon UITheme::getFileIcon(std::string filename) { return Image; } return File; -} \ No newline at end of file +} diff --git a/src/components/UITheme.h b/src/components/UITheme.h index dc3e55f0..3acf8059 100644 --- a/src/components/UITheme.h +++ b/src/components/UITheme.h @@ -1,12 +1,11 @@ #pragma once #include +#include #include "CrossPointSettings.h" #include "components/themes/BaseTheme.h" -class MappedInputManager; - class UITheme { // Static instance static UITheme instance; @@ -26,7 +25,7 @@ class UITheme { private: const ThemeMetrics* currentMetrics; - const BaseTheme* currentTheme; + std::unique_ptr currentTheme; }; // Helper macro to access current theme