Skip to content

Commit 3238a44

Browse files
committed
free parsed themes to not show as mem leak
1 parent 98c8ca9 commit 3238a44

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

src/GlobalPrefs.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,10 @@ void SetFileStatePath(FileState* fs, const WCHAR* path) {
144144
Themes* ParseThemes(const char* data) {
145145
return (Themes*)DeserializeStruct(&gThemesInfo, data);
146146
}
147+
148+
void FreeParsedThemes(Themes* themes) {
149+
if (!themes) {
150+
return;
151+
}
152+
FreeStruct(&gThemesInfo, themes);
153+
}

src/GlobalPrefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ void SetFileStatePath(FileState* fs, const char* path);
2323
// void SetFileStatePath(FileState* fs, const WCHAR* path);
2424

2525
Themes* ParseThemes(const char* data);
26+
void FreeParsedThemes(Themes* themes);
2627

2728
#define GetPrefsColor(name) GetParsedColor(name, name##Parsed)

src/SumatraStartup.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,7 @@ int APIENTRY WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE, _In_ LPSTR, _
14691469
ShutdownCleanup();
14701470
EngineEbookCleanup();
14711471
FreeCustomCommands();
1472+
FreeThemes();
14721473

14731474
// it's still possible to crash after this (destructors of static classes,
14741475
// atexit() code etc.) point, but it's very unlikely

src/Theme.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,25 @@ static int gThemeCount;
146146
static int gCurrThemeIndex = 0;
147147
static Theme* gCurrentTheme = nullptr;
148148
static Theme* gThemeLight = nullptr;
149+
static Themes* gParsedThemes = nullptr;
149150

150151
bool IsCurrentThemeDefault() {
151152
return gCurrThemeIndex == 0;
152153
}
153154

155+
void FreeThemes() {
156+
delete gThemes; // no need to free members, they are owned by gParsedThemes
157+
gThemes = nullptr;
158+
FreeParsedThemes(gParsedThemes);
159+
gParsedThemes = nullptr;
160+
}
161+
154162
void CreateThemeCommands() {
155-
delete gThemes;
163+
FreeThemes();
164+
156165
gThemes = new Vec<Theme*>();
157-
auto themes = ParseThemes(themesTxt);
158-
for (Theme* theme : *themes->themes) {
166+
gParsedThemes = ParseThemes(themesTxt);
167+
for (Theme* theme : *gParsedThemes->themes) {
159168
gThemes->Append(theme);
160169
}
161170

src/Theme.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ COLORREF ThemeNotificationsHighlightTextColor();
2121
COLORREF ThemeNotificationsProgressColor();
2222
bool ThemeColorizeControls();
2323
bool IsCurrentThemeDefault();
24+
void FreeThemes();
2425

2526
extern int gFirstSetThemeCmdId;
2627
extern int gLastSetThemeCmdId;

0 commit comments

Comments
 (0)