Skip to content

Commit 2947e27

Browse files
committed
Properly close multiple tabs at once
Free the terminals from the last to the first, otherwise the indexes are changed during deconstuction, which leads to a segmentation fault. Closes: #134
1 parent ac5e36f commit 2947e27

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/lxterminal.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ static void terminal_close_window_activate_event(GtkAction * action, LXTerminal
486486

487487
/* Play it safe and delete tabs one by one. */
488488
for (len = terminal->terms->len; len; len--) {
489-
Term *term = g_ptr_array_index(terminal->terms, 0);
489+
Term *term = g_ptr_array_index(terminal->terms, len - 1);
490490
#if VTE_CHECK_VERSION (0, 38, 0)
491491
terminal_child_exited_event(VTE_TERMINAL(term->vte), 0, term);
492492
#else
@@ -841,7 +841,23 @@ static void terminal_window_title_changed_event(GtkWidget * vte, Term * term)
841841
/* Handler for "delete-event" signal on a LXTerminal. */
842842
static gboolean terminal_close_window_confirmation_event(GtkWidget * widget, GdkEventButton * event, LXTerminal * terminal)
843843
{
844-
return !terminal_close_window_confirmation_dialog(terminal);
844+
guint len;
845+
846+
if (!terminal_close_window_confirmation_dialog(terminal)) {
847+
return TRUE;
848+
}
849+
850+
/* Play it safe and delete tabs one by one. */
851+
for (len = terminal->terms->len; len; len--) {
852+
Term *term = g_ptr_array_index(terminal->terms, len - 1);
853+
#if VTE_CHECK_VERSION (0, 38, 0)
854+
terminal_child_exited_event(VTE_TERMINAL(term->vte), 0, term);
855+
#else
856+
terminal_child_exited_event(VTE_TERMINAL(term->vte), term);
857+
#endif
858+
}
859+
860+
return FALSE;
845861
}
846862

847863
/* Display closing tabs warning */

0 commit comments

Comments
 (0)