From 9ba7f67238dad49e36e5754df9784f47f2c4881e Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Thu, 7 Jul 2016 17:53:43 +0200 Subject: [PATCH] Don't require plugin key group name and label strings to be static Take a copy of the strings not to require them to live live as long as the plugin does. This is mostly useful for plugins implemented in dynamic languages (e.g. through a plugin proxy), as most C plugins will use a static string here; but it makes the API more straightforward and avoids odd issues if any plugin doesn't use static strings here, even C ones. Closes #1125. --- src/keybindings.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/keybindings.c b/src/keybindings.c index 4eb3a90a73..cdc2e9cd2e 100644 --- a/src/keybindings.c +++ b/src/keybindings.c @@ -262,8 +262,9 @@ static void add_kb_group(GeanyKeyGroup *group, { g_ptr_array_add(keybinding_groups, group); - group->name = name; - group->label = label; + /* as for items, we only require duplicated name and label for plugins */ + group->name = plugin ? g_strdup(name) : name; + group->label = plugin ? g_strdup(label) : label; group->callback = callback; group->cb_func = NULL; group->cb_data = NULL; @@ -722,6 +723,9 @@ static void free_key_group(gpointer item) if (group->cb_data_destroy) group->cb_data_destroy(group->cb_data); g_free(group->plugin_keys); + /* we allocated those in add_kb_group() as it's a plugin group */ + g_free((gchar *) group->name); + g_free((gchar *) group->label); g_free(group); } }