[Xfce4-commits] <libxfce4ui:master> Fix memory corruption in register function (bug #5892).
Nick Schermer
noreply at xfce.org
Tue Jan 4 21:28:01 CET 2011
Updating branch refs/heads/master
to 4bded49a31e58b85305d176490d8e08f7a5408da (commit)
from 406dcf32d4fdecdb76d31539aef655c11239038b (commit)
commit 4bded49a31e58b85305d176490d8e08f7a5408da
Author: Nick Schermer <nick at xfce.org>
Date: Tue Jan 4 21:25:38 2011 +0100
Fix memory corruption in register function (bug #5892).
Also cleanup the function a bit.
libxfce4kbd-private/xfce-shortcuts-provider.c | 35 +++++++++++++-----------
1 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/libxfce4kbd-private/xfce-shortcuts-provider.c b/libxfce4kbd-private/xfce-shortcuts-provider.c
index b2522ef..061c1fe 100644
--- a/libxfce4kbd-private/xfce-shortcuts-provider.c
+++ b/libxfce4kbd-private/xfce-shortcuts-provider.c
@@ -235,33 +235,36 @@ static void
xfce_shortcuts_provider_register (XfceShortcutsProvider *provider)
{
gchar **provider_names;
- const gchar **names;
+ gchar **names;
gboolean already_registered = FALSE;
- gint length;
gint i;
+ const gchar *name;
g_return_if_fail (XFCE_IS_SHORTCUTS_PROVIDER (provider));
- provider_names = xfconf_channel_get_string_list (provider->priv->channel, "/providers");
-
- for (i = 0; provider_names != NULL && provider_names[i] != NULL; ++i)
- if (G_UNLIKELY (g_str_equal (provider_names[i], xfce_shortcuts_provider_get_name (provider))))
- {
- already_registered = TRUE;
- break;
- }
+ name = xfce_shortcuts_provider_get_name (provider);
+ if (G_UNLIKELY (name == NULL))
+ return;
- length = i;
+ provider_names = xfconf_channel_get_string_list (provider->priv->channel, "/providers");
+ if (provider_names != NULL)
+ for (i = 0; !already_registered && provider_names[i] != NULL; i++)
+ already_registered = g_str_equal (provider_names[i], name);
if (G_UNLIKELY (!already_registered))
{
- names = g_new0 (const gchar *, length + 1);
- for (i = 0; provider_names != NULL && provider_names[i] != NULL; ++i)
- names[i] = provider_names[i];
- names[i++] = xfce_shortcuts_provider_get_name (provider);
+ names = g_new0 (gchar *, g_strv_length (provider_names) + 2);
+ i = 0;
+
+ if (provider_names != NULL)
+ for (; provider_names[i] != NULL; i++)
+ names[i] = provider_names[i];
+
+ names[i++] = (gchar *) name;
names[i] = NULL;
- xfconf_channel_set_string_list (provider->priv->channel, "/providers", names);
+ xfconf_channel_set_string_list (provider->priv->channel, "/providers",
+ (const gchar * const *) names);
g_free (names);
}
More information about the Xfce4-commits
mailing list