Fix memory leaks in cb_inputbar_activate and handle empty bookmark names in

cmd_bookmark.

Thanks to Pavel Borzenkov for noticing the issue with empty bookmark names.
This commit is contained in:
Sebastian Ramacher 2011-07-07 14:00:10 +02:00
parent 2e7dac75de
commit 52c8bedc60

View file

@ -3079,6 +3079,13 @@ cmd_bookmark(int argc, char** argv)
id = g_string_append(id, argv[i]); id = g_string_append(id, argv[i]);
} }
if(strlen(id->str) == 0)
{
notify(WARNING, "Can't set bookmark: bookmark name is empty");
g_string_free(id, TRUE);
return FALSE;
}
if(is_reserved_bm_name(id->str)) if(is_reserved_bm_name(id->str))
{ {
notify(WARNING, "Can't set bookmark: reserved bookmark name"); notify(WARNING, "Can't set bookmark: reserved bookmark name");
@ -4351,6 +4358,8 @@ cb_inputbar_activate(GtkEntry* entry, gpointer data)
{ {
gchar *input = gtk_editable_get_chars(GTK_EDITABLE(entry), 1, -1); gchar *input = gtk_editable_get_chars(GTK_EDITABLE(entry), 1, -1);
gchar **tokens = g_strsplit(input, " ", -1); gchar **tokens = g_strsplit(input, " ", -1);
g_free(input);
gchar *command = tokens[0]; gchar *command = tokens[0];
int length = g_strv_length(tokens); int length = g_strv_length(tokens);
int i = 0; int i = 0;
@ -4361,6 +4370,7 @@ cb_inputbar_activate(GtkEntry* entry, gpointer data)
if(length < 1) if(length < 1)
{ {
isc_abort(NULL); isc_abort(NULL);
g_strfreev(tokens);
return FALSE; return FALSE;
} }
@ -4378,12 +4388,14 @@ cb_inputbar_activate(GtkEntry* entry, gpointer data)
if(special_commands[i].always == 1) if(special_commands[i].always == 1)
{ {
isc_abort(NULL); isc_abort(NULL);
g_strfreev(tokens);
return TRUE; return TRUE;
} }
retv = special_commands[i].function(input, &(special_commands[i].argument)); retv = special_commands[i].function(input, &(special_commands[i].argument));
if(retv) isc_abort(NULL); if(retv) isc_abort(NULL);
gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.view)); gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.view));
g_strfreev(tokens);
return TRUE; return TRUE;
} }
} }
@ -4413,6 +4425,7 @@ cb_inputbar_activate(GtkEntry* entry, gpointer data)
isc_completion(&arg); isc_completion(&arg);
gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.view)); gtk_widget_grab_focus(GTK_WIDGET(Zathura.UI.view));
g_strfreev(tokens);
return TRUE; return TRUE;
} }