From 374635a1a03ea169fdebc04ef58afe8d45047b62 Mon Sep 17 00:00:00 2001 From: Matt Borgerson Date: Fri, 11 Jun 2021 18:55:47 -0700 Subject: [PATCH] ui: Fix incorrect free in xemu_settings_set_string --- ui/xemu-settings.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/xemu-settings.c b/ui/xemu-settings.c index 648f0f4708..7c1bb1c827 100644 --- a/ui/xemu-settings.c +++ b/ui/xemu-settings.c @@ -145,7 +145,9 @@ static void *xemu_settings_get_field(enum xemu_settings_keys key, enum config_ty int xemu_settings_set_string(enum xemu_settings_keys key, const char *str) { char **field_str = (char **)xemu_settings_get_field(key, CONFIG_TYPE_STRING); - free(*field_str); + if (*field_str) { + free(*field_str); + } *field_str = strdup(str); return 0; } @@ -369,6 +371,7 @@ void xemu_settings_load(void) g_settings = malloc(sizeof(struct xemu_settings)); assert(g_settings != NULL); + memset(g_settings, 0, sizeof(struct xemu_settings)); xemu_settings_init_default(g_settings); // Parse configuration file