From 28247ba65dd61910a7c1d03122818abaa5620611 Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Mon, 21 Mar 2022 12:06:49 +0000 Subject: [PATCH] (config_file) Prevent hash map corruption when calling config_unset() - This is a workaround for the broken 'RHMAP_DEL_STR()' implementation in rhmap.h - This commit should be reverted when rhmap.h is fixed --- libretro-common/file/config_file.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libretro-common/file/config_file.c b/libretro-common/file/config_file.c index 0b90b7a7a8..5953b0f7e7 100644 --- a/libretro-common/file/config_file.c +++ b/libretro-common/file/config_file.c @@ -1242,8 +1242,6 @@ void config_unset(config_file_t *conf, const char *key) if (!entry) return; - (void)RHMAP_DEL_STR(conf->entries_map, entry->key); - if (entry->key) free(entry->key); @@ -1253,6 +1251,16 @@ void config_unset(config_file_t *conf, const char *key) entry->key = NULL; entry->value = NULL; conf->modified = true; + + /* TODO/FIXME: We want to call RHMAP_DEL_STR() + * here to remove the current entry from the + * internal hash map - but RHMAP_DEL_STR() does + * not work correctly and causes hash map corruption. + * We therefore work around this by leaving the + * entry in the hash map, but setting its value + * to NULL... */ + entry = NULL; + RHMAP_SET_STR(conf->entries_map, key, entry); } void config_set_path(config_file_t *conf, const char *entry, const char *val) @@ -1460,7 +1468,7 @@ void config_file_dump(config_file_t *conf, FILE *file, bool sort) bool config_entry_exists(config_file_t *conf, const char *entry) { - return (bool)RHMAP_HAS_STR(conf->entries_map, entry); + return !!RHMAP_GET_STR(conf->entries_map, entry); } bool config_get_entry_list_head(config_file_t *conf,