1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

core: fix crash on /reload weechat

The problem was introduced in commit eef3b57075
which was storing split commands inside keys themselves (for optimization).

This causes a problem when weechat.conf is reloaded, because all keys are
then deleted and created again, which removes the array of commands which
is currently used. And then it leads to a crash of WeeChat.

This commit reverts this behavior and the key commands are split when they
are executed.
This commit is contained in:
Sebastien Helleu
2014-03-27 07:53:01 +01:00
parent d129b39b86
commit 6a5f0fbc07
2 changed files with 46 additions and 51 deletions
+46 -50
View File
@@ -640,7 +640,6 @@ gui_key_new (struct t_gui_buffer *buffer, int context, const char *key,
if (!new_key->key)
new_key->key = strdup (key);
new_key->command = strdup (command);
new_key->commands = string_split_command (command, ';');
gui_key_set_areas (new_key);
gui_key_set_score (new_key);
@@ -1032,7 +1031,7 @@ gui_key_focus_command (const char *key, int context,
struct t_gui_key *ptr_key;
int i, errors, matching, debug, rc;
long unsigned int value;
char *command;
char *command, **commands;
const char *str_buffer;
struct t_hashtable *hashtable;
struct t_weelist *list_keys;
@@ -1109,48 +1108,53 @@ gui_key_focus_command (const char *key, int context,
gui_chat_printf (NULL, _("Command for key: \"%s\""),
ptr_key->command);
}
if (ptr_key->commands)
if (ptr_key->command)
{
for (i = 0; ptr_key->commands[i]; i++)
commands = string_split_command (ptr_key->command, ';');
if (commands)
{
if (string_strncasecmp (ptr_key->commands[i], "hsignal:", 8) == 0)
for (i = 0; commands[i]; i++)
{
if (ptr_key->commands[i][8])
if (string_strncasecmp (commands[i], "hsignal:", 8) == 0)
{
if (debug)
{
gui_chat_printf (NULL,
_("Sending hsignal: \"%s\""),
ptr_key->commands[i] + 8);
}
(void) hook_hsignal_send (ptr_key->commands[i] + 8,
hashtable);
}
}
else
{
command = string_replace_with_callback (ptr_key->commands[i],
"${", "}",
&gui_key_focus_command_replace_cb,
hashtable,
&errors);
if (command)
{
if (errors == 0)
if (commands[i][8])
{
if (debug)
{
gui_chat_printf (NULL,
_("Executing command: \"%s\" "
"on buffer \"%s\""),
command,
ptr_buffer->full_name);
_("Sending hsignal: \"%s\""),
commands[i] + 8);
}
input_data (ptr_buffer, command);
(void) hook_hsignal_send (commands[i] + 8,
hashtable);
}
}
else
{
command = string_replace_with_callback (commands[i],
"${", "}",
&gui_key_focus_command_replace_cb,
hashtable,
&errors);
if (command)
{
if (errors == 0)
{
if (debug)
{
gui_chat_printf (NULL,
_("Executing command: \"%s\" "
"on buffer \"%s\""),
command,
ptr_buffer->full_name);
}
input_data (ptr_buffer, command);
}
free (command);
}
free (command);
}
}
string_free_split (commands);
}
}
hashtable_free (hashtable);
@@ -1248,7 +1252,7 @@ gui_key_pressed (const char *key_str)
{
int i, first_key, context, length, length_key, rc, signal_sent;
struct t_gui_key *ptr_key;
char *pos, signal_name[128];
char *pos, signal_name[128], **commands;
signal_sent = 0;
@@ -1338,12 +1342,16 @@ gui_key_pressed (const char *key_str)
WEECHAT_HOOK_SIGNAL_STRING,
gui_key_combo_buffer);
gui_key_combo_buffer[0] = '\0';
if ((rc != WEECHAT_RC_OK_EAT) && ptr_key->commands)
if ((rc != WEECHAT_RC_OK_EAT) && ptr_key->command)
{
for (i = 0; ptr_key->commands[i]; i++)
commands = string_split_command (ptr_key->command, ';');
if (commands)
{
input_data (gui_current_window->buffer,
ptr_key->commands[i]);
for (i = 0; commands[i]; i++)
{
input_data (gui_current_window->buffer, commands[i]);
}
string_free_split (commands);
}
}
}
@@ -1412,8 +1420,6 @@ gui_key_free (struct t_gui_key **keys, struct t_gui_key **last_key,
free (key->area_key);
if (key->command)
free (key->command);
if (key->commands)
string_free_split (key->commands);
/* remove key from keys list */
if (key->prev_key)
@@ -1856,7 +1862,6 @@ gui_key_hdata_key_cb (void *data, const char *hdata_name)
HDATA_VAR(struct t_gui_key, area_name, POINTER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_key, area_key, STRING, 0, NULL, NULL);
HDATA_VAR(struct t_gui_key, command, STRING, 0, NULL, NULL);
HDATA_VAR(struct t_gui_key, commands, POINTER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_key, score, INTEGER, 0, NULL, NULL);
HDATA_VAR(struct t_gui_key, prev_key, POINTER, 0, NULL, hdata_name);
HDATA_VAR(struct t_gui_key, next_key, POINTER, 0, NULL, hdata_name);
@@ -1945,7 +1950,7 @@ gui_key_add_to_infolist (struct t_infolist *infolist, struct t_gui_key *key)
void
gui_key_print_log_key (struct t_gui_key *key, const char *prefix)
{
int area, i;
int area;
log_printf ("%s[key (addr:0x%lx)]", prefix, key);
log_printf ("%s key. . . . . . . . : '%s'", prefix, key->key);
@@ -1959,15 +1964,6 @@ gui_key_print_log_key (struct t_gui_key *key, const char *prefix)
}
log_printf ("%s area_key . . . . . : '%s'", prefix, key->area_key);
log_printf ("%s command. . . . . . : '%s'", prefix, key->command);
log_printf ("%s commands . . . . . : 0x%lx", prefix, key->commands);
if (key->commands)
{
for (i = 0; key->commands[i]; i++)
{
log_printf ("%s commands[%03d]. . : '%s'",
prefix, i, key->commands[i]);
}
}
log_printf ("%s score. . . . . . . : %d", prefix, key->score);
log_printf ("%s prev_key . . . . . : 0x%lx", prefix, key->prev_key);
log_printf ("%s next_key . . . . . : 0x%lx", prefix, key->next_key);
-1
View File
@@ -59,7 +59,6 @@ struct t_gui_key
char *area_name[2]; /* name of areas (for cursor/mouse) */
char *area_key; /* key after area (after ":") */
char *command; /* associated command */
char **commands; /* command split on ';' */
int score; /* score, for sorting keys */
struct t_gui_key *prev_key; /* link to previous key */
struct t_gui_key *next_key; /* link to next key */