From ab3d2a1ad9440c9e50d56da4dca69458799a93f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Janiszewski?= Date: Wed, 13 Jan 2016 17:42:34 +0100 Subject: [PATCH] Release config on closing to limit leaked memory --- src/config.c | 15 +++++++++++++++ src/config.h | 1 + src/interface/themes.c | 12 +++++++++--- src/openrct2.c | 1 + 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index a5c95af976..4cba3a83c7 100644 --- a/src/config.c +++ b/src/config.c @@ -396,6 +396,21 @@ void config_set_defaults() } } +void config_release() +{ + for (int i = 0; i < countof(_sectionDefinitions); i++) { + config_section_definition *section = &_sectionDefinitions[i]; + for (int j = 0; j < section->property_definitions_count; j++) { + config_property_definition *property = §ion->property_definitions[j]; + value_union *destValue = (value_union*)((size_t)section->base_address + (size_t)property->offset); + if (property->type == CONFIG_VALUE_TYPE_STRING) { + utf8 **dst = (utf8**)&(destValue->value_string); + SafeFree(*dst); + } + } + } +} + void config_get_default_path(utf8 *outPath) { platform_get_user_directory(outPath, NULL); diff --git a/src/config.h b/src/config.h index 9d4f717bd0..fb00eb8814 100644 --- a/src/config.h +++ b/src/config.h @@ -339,6 +339,7 @@ extern uint16 gShortcutKeys[SHORTCUT_COUNT]; void config_get_default_path(utf8 *outPath); void config_set_defaults(); +void config_release(); bool config_open_default(); bool config_save_default(); diff --git a/src/interface/themes.c b/src/interface/themes.c index 96ef4f6742..d46cb93cbf 100644 --- a/src/interface/themes.c +++ b/src/interface/themes.c @@ -171,18 +171,24 @@ void colour_scheme_update_by_class(rct_window *window, rct_windowclass classific window->flags |= WF_TRANSPARENT; } +static void theme_set_preset_string(const utf8string preset) +{ + SafeFree(gConfigInterface.current_theme_preset); + gConfigInterface.current_theme_preset = strdup(preset); +} + void theme_change_preset(int preset) { if (preset >= 0 && preset < gConfigThemes.num_presets) { switch (preset) { case 0: - gConfigInterface.current_theme_preset = "*RCT2"; + theme_set_preset_string("*RCT2"); break; case 1: - gConfigInterface.current_theme_preset = "*RCT1"; + theme_set_preset_string("*RCT1"); break; default: - gConfigInterface.current_theme_preset = gConfigThemes.presets[preset].name; + theme_set_preset_string(gConfigThemes.presets[preset].name); break; } gCurrentTheme = preset; diff --git a/src/openrct2.c b/src/openrct2.c index f519ea9863..16e1bf1db9 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -322,6 +322,7 @@ void openrct2_dispose() network_close(); http_dispose(); language_close_all(); + config_release(); platform_free(); }