From 0545f8a1eb3c1b392e7d3bbe934c665b41c7a0d2 Mon Sep 17 00:00:00 2001 From: Pierre Labastie Date: Tue, 29 Aug 2023 23:07:59 +0200 Subject: [PATCH] Fix a double free when there are errors When calling g_dbus_method_invocation _xxxerror, the "invocation" variable is freed, so blocaled_locale1_complete_set_locale shouldn't be called afterwards. But with the "unlock:" logic, this is what was happening. This is pretty amazing that tests were passing with older versions of glib... --- src/localed.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/localed.c b/src/localed.c index 76d2b47..cc6f852 100644 --- a/src/localed.c +++ b/src/localed.c @@ -932,12 +932,11 @@ on_handle_set_locale_authorized_cb (GObject *source_object, } blocaled_locale1_set_locale (locale1, (const gchar * const *) locale); + blocaled_locale1_complete_set_locale (locale1, data->invocation); unlock: G_UNLOCK (locale); - blocaled_locale1_complete_set_locale (locale1, data->invocation); - out: shell_parser_free (locale_file_parsed); /* g_strfreev (locale_values) will leak, since it stops at first NULL value */ @@ -1049,6 +1048,7 @@ on_handle_set_vconsole_keyboard_authorized_cb (GObject *source_object, filename = g_file_get_path (kbd_model_map_file); g_printerr ("Failed to find conversion entry for console keymap '%s' in '%s'\n", data->vconsole_keymap, filename); g_free (filename); + blocaled_locale1_complete_set_vconsole_keyboard (locale1, data->invocation); goto unlock; } else { unsigned int failure_score = 0; @@ -1083,13 +1083,13 @@ on_handle_set_vconsole_keyboard_authorized_cb (GObject *source_object, } } + blocaled_locale1_complete_set_vconsole_keyboard (locale1, data->invocation); + unlock: if (data->convert) G_UNLOCK (xorg_conf); G_UNLOCK (keymaps); - blocaled_locale1_complete_set_vconsole_keyboard (locale1, data->invocation); - out: if (kbd_model_map != NULL) g_list_free_full (kbd_model_map, (GDestroyNotify)kbd_model_map_entry_free); @@ -1229,13 +1229,13 @@ on_handle_set_x11_keyboard_authorized_cb (GObject *source_object, } } + blocaled_locale1_complete_set_x11_keyboard (locale1, data->invocation); + unlock: if (data->convert) G_UNLOCK (keymaps); G_UNLOCK (xorg_conf); - blocaled_locale1_complete_set_x11_keyboard (locale1, data->invocation); - out: if (kbd_model_map != NULL) g_list_free_full (kbd_model_map, (GDestroyNotify)kbd_model_map_entry_free); From f1b5e21a04acf00934cc55cc1f2facd87606c35e Mon Sep 17 00:00:00 2001 From: Pierre Labastie Date: Wed, 30 Aug 2023 10:16:35 +0200 Subject: [PATCH] Add a "finish" label in callbacks When a call back finishes without error, or if there is an error but we don't use g_dbus_method_invocation_xxxerror, we need to call blocaled_locale1_complete_xxx. Since the code may come from various places, add a "finish" label before this call. We only use a goto once, but it may be handy to have it if we add further code paths. --- src/localed.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/localed.c b/src/localed.c index cc6f852..7c03379 100644 --- a/src/localed.c +++ b/src/localed.c @@ -15,7 +15,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - Modified in 2019, 2020 by Pierre Labastie. See git log + Modified in 2019, 2020, 2023 by Pierre Labastie. See git log */ #include @@ -932,6 +932,7 @@ on_handle_set_locale_authorized_cb (GObject *source_object, } blocaled_locale1_set_locale (locale1, (const gchar * const *) locale); + finish: blocaled_locale1_complete_set_locale (locale1, data->invocation); unlock: @@ -1048,8 +1049,7 @@ on_handle_set_vconsole_keyboard_authorized_cb (GObject *source_object, filename = g_file_get_path (kbd_model_map_file); g_printerr ("Failed to find conversion entry for console keymap '%s' in '%s'\n", data->vconsole_keymap, filename); g_free (filename); - blocaled_locale1_complete_set_vconsole_keyboard (locale1, data->invocation); - goto unlock; + goto finish; } else { unsigned int failure_score = 0; @@ -1083,6 +1083,7 @@ on_handle_set_vconsole_keyboard_authorized_cb (GObject *source_object, } } + finish: blocaled_locale1_complete_set_vconsole_keyboard (locale1, data->invocation); unlock: @@ -1229,6 +1230,7 @@ on_handle_set_x11_keyboard_authorized_cb (GObject *source_object, } } + finish: blocaled_locale1_complete_set_x11_keyboard (locale1, data->invocation); unlock: