Store "cfg" on stack and destory it once finished

This commit is contained in:
friedkeenan 2018-09-10 20:49:11 -05:00 committed by GitHub
parent 6bcfbd66cf
commit 667ef4461e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,27 +47,26 @@ void themeStartup(ThemePreset preset) {
};
theme_t *themeDefault;
config_t *cfg = NULL;
cfg = (config_t *) malloc(sizeof(config_t));
config_init(cfg);
config_t cfg = {0};
config_init(&cfg);
config_setting_t *theme;
color_t text, frontWave, middleWave, backWave, background, highlight, separator;
int waveBlending;
const char *AText, *BText;
bool good_cfg=config_read_file(cfg, "/hbtheme.cfg");
bool good_cfg=config_read_file(&cfg, "/hbtheme.cfg");
switch (preset) {
case THEME_PRESET_LIGHT:
default:
themeDefault = &themeLight;
if (good_cfg)
theme = config_lookup(cfg, "lightTheme");
theme = config_lookup(&cfg, "lightTheme");
break;
case THEME_PRESET_DARK:
themeDefault = &themeDark;
if (good_cfg)
theme = config_lookup(cfg, "darkTheme");
theme = config_lookup(&cfg, "darkTheme");
break;
}
@ -114,4 +113,5 @@ void themeStartup(ThemePreset preset) {
} else {
themeCurrent = *themeDefault;
}
config_destroy(&cfg);
}