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<BaseTheme>` so the
  previous theme object is automatically deleted on reassignment
- Added `<memory>` 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 <dave@daveallie.com>
This commit is contained in:
jpirnay
2026-02-19 12:13:12 +01:00
committed by GitHub
parent 10b7769865
commit 3c1bd77813
2 changed files with 6 additions and 7 deletions

View File

@@ -32,17 +32,17 @@ void UITheme::setTheme(CrossPointSettings::UI_THEME type) {
switch (type) { switch (type) {
case CrossPointSettings::UI_THEME::CLASSIC: case CrossPointSettings::UI_THEME::CLASSIC:
LOG_DBG("UI", "Using Classic theme"); LOG_DBG("UI", "Using Classic theme");
currentTheme = new BaseTheme(); currentTheme = std::make_unique<BaseTheme>();
currentMetrics = &BaseMetrics::values; currentMetrics = &BaseMetrics::values;
break; break;
case CrossPointSettings::UI_THEME::LYRA: case CrossPointSettings::UI_THEME::LYRA:
LOG_DBG("UI", "Using Lyra theme"); LOG_DBG("UI", "Using Lyra theme");
currentTheme = new LyraTheme(); currentTheme = std::make_unique<LyraTheme>();
currentMetrics = &LyraMetrics::values; currentMetrics = &LyraMetrics::values;
break; break;
case CrossPointSettings::UI_THEME::LYRA_3_COVERS: case CrossPointSettings::UI_THEME::LYRA_3_COVERS:
LOG_DBG("UI", "Using Lyra 3 Covers theme"); LOG_DBG("UI", "Using Lyra 3 Covers theme");
currentTheme = new Lyra3CoversTheme(); currentTheme = std::make_unique<Lyra3CoversTheme>();
currentMetrics = &Lyra3CoversMetrics::values; currentMetrics = &Lyra3CoversMetrics::values;
break; break;
} }
@@ -89,4 +89,4 @@ UIIcon UITheme::getFileIcon(std::string filename) {
return Image; return Image;
} }
return File; return File;
} }

View File

@@ -1,12 +1,11 @@
#pragma once #pragma once
#include <functional> #include <functional>
#include <memory>
#include "CrossPointSettings.h" #include "CrossPointSettings.h"
#include "components/themes/BaseTheme.h" #include "components/themes/BaseTheme.h"
class MappedInputManager;
class UITheme { class UITheme {
// Static instance // Static instance
static UITheme instance; static UITheme instance;
@@ -26,7 +25,7 @@ class UITheme {
private: private:
const ThemeMetrics* currentMetrics; const ThemeMetrics* currentMetrics;
const BaseTheme* currentTheme; std::unique_ptr<BaseTheme> currentTheme;
}; };
// Helper macro to access current theme // Helper macro to access current theme