ref(theme): ensure clean reinitialization and explicitly initialize static vars
Some checks failed
CI / Check spelling (pull_request) Successful in 18s
CI / Check coding style (pull_request) Failing after 28s
CI / Linux (debian) (pull_request) Successful in 9m39s
CI / Linux (ubuntu) (pull_request) Successful in 9m59s
CI / Linux (fedora) (pull_request) Successful in 10m38s
CI / Linux (arch) (pull_request) Successful in 16m6s
Some checks failed
CI / Check spelling (pull_request) Successful in 18s
CI / Check coding style (pull_request) Failing after 28s
CI / Linux (debian) (pull_request) Successful in 9m39s
CI / Linux (ubuntu) (pull_request) Successful in 9m59s
CI / Linux (fedora) (pull_request) Successful in 10m38s
CI / Linux (arch) (pull_request) Successful in 16m6s
Improves code robustness by calling _theme_close() in theme_init() when the theme was already initialized, preventing potential memory leaks or inconsistent state. Closes #4
This commit is contained in:
@@ -56,9 +56,9 @@
|
||||
#include "config/preferences.h"
|
||||
#include "config/color.h"
|
||||
|
||||
static GString* theme_loc;
|
||||
static GKeyFile* theme;
|
||||
static GHashTable* defaults;
|
||||
static GString* theme_loc = NULL;
|
||||
static GKeyFile* theme = NULL;
|
||||
static GHashTable* defaults = NULL;
|
||||
|
||||
static void _load_preferences(void);
|
||||
static void _theme_list_dir(const gchar* const dir, GSList** result);
|
||||
@@ -86,6 +86,12 @@ _theme_close(void)
|
||||
void
|
||||
theme_init(const char* const theme_name)
|
||||
{
|
||||
if(defaults || theme_loc || theme) {
|
||||
log_warning("theme_init(): Detected non-NULL state (theme=%p, theme_loc=%p, defaults=%p). Cleaning up previous initialization.",
|
||||
theme, theme_loc, defaults);
|
||||
_theme_close();
|
||||
}
|
||||
|
||||
if (!_theme_load_file(theme_name)) {
|
||||
log_error("Loading theme %s failed.", theme_name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user