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