1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Release config on closing to limit leaked memory

This commit is contained in:
Michał Janiszewski
2016-01-13 17:42:34 +01:00
parent 57420cbc66
commit ab3d2a1ad9
4 changed files with 26 additions and 3 deletions

View File

@@ -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 = &section->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);

View File

@@ -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();

View File

@@ -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;

View File

@@ -322,6 +322,7 @@ void openrct2_dispose()
network_close();
http_dispose();
language_close_all();
config_release();
platform_free();
}