A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

jpirnay
Dave Allie
and committed by
GitHub
3c1bd778 10b77698

+6 -7
+4 -4
src/components/UITheme.cpp
··· 32 32 switch (type) { 33 33 case CrossPointSettings::UI_THEME::CLASSIC: 34 34 LOG_DBG("UI", "Using Classic theme"); 35 - currentTheme = new BaseTheme(); 35 + currentTheme = std::make_unique<BaseTheme>(); 36 36 currentMetrics = &BaseMetrics::values; 37 37 break; 38 38 case CrossPointSettings::UI_THEME::LYRA: 39 39 LOG_DBG("UI", "Using Lyra theme"); 40 - currentTheme = new LyraTheme(); 40 + currentTheme = std::make_unique<LyraTheme>(); 41 41 currentMetrics = &LyraMetrics::values; 42 42 break; 43 43 case CrossPointSettings::UI_THEME::LYRA_3_COVERS: 44 44 LOG_DBG("UI", "Using Lyra 3 Covers theme"); 45 - currentTheme = new Lyra3CoversTheme(); 45 + currentTheme = std::make_unique<Lyra3CoversTheme>(); 46 46 currentMetrics = &Lyra3CoversMetrics::values; 47 47 break; 48 48 } ··· 89 89 return Image; 90 90 } 91 91 return File; 92 - } 92 + }
+2 -3
src/components/UITheme.h
··· 1 1 #pragma once 2 2 3 3 #include <functional> 4 + #include <memory> 4 5 5 6 #include "CrossPointSettings.h" 6 7 #include "components/themes/BaseTheme.h" 7 - 8 - class MappedInputManager; 9 8 10 9 class UITheme { 11 10 // Static instance ··· 26 25 27 26 private: 28 27 const ThemeMetrics* currentMetrics; 29 - const BaseTheme* currentTheme; 28 + std::unique_ptr<BaseTheme> currentTheme; 30 29 }; 31 30 32 31 // Helper macro to access current theme