From c1aa51fa9c9143729455c2fe19b70965abd82375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Wed, 24 Sep 2014 21:45:01 +0200 Subject: [PATCH] core: fix crash on buffer close when option weechat.look.hotlist_remove is set to "merged" (closes #199) --- ChangeLog.asciidoc | 2 ++ src/gui/curses/gui-curses-window.c | 2 +- src/gui/gui-buffer.c | 6 +++--- src/gui/gui-hotlist.c | 12 ++++++++---- src/gui/gui-hotlist.h | 3 ++- src/gui/gui-input.c | 2 +- src/gui/gui-window.c | 2 +- 7 files changed, 18 insertions(+), 11 deletions(-) diff --git a/ChangeLog.asciidoc b/ChangeLog.asciidoc index bb86f0b37..8c02c8a5d 100644 --- a/ChangeLog.asciidoc +++ b/ChangeLog.asciidoc @@ -28,6 +28,8 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] === Bugs fixed +* core: fix crash on buffer close when option weechat.look.hotlist_remove is + set to "merged" (closes #199) * core: fix highlight of IRC action messages when option irc.look.nick_mode is set to "action" or "both" (closes #206) * core: fix compilation of plugin API functions (macros) when compiler diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index 593c7f31d..af0813e86 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -1224,7 +1224,7 @@ gui_window_switch_to_buffer (struct t_gui_window *window, gui_buffer_compute_num_displayed (); if (!weechat_upgrading && (old_buffer != buffer)) - gui_hotlist_remove_buffer (buffer); + gui_hotlist_remove_buffer (buffer, 0); gui_bar_window_remove_unused_bars (window); gui_bar_window_add_missing_bars (window); diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index 4794fd12f..3185c432c 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -1730,7 +1730,7 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property, if (error && !error[0]) { if (number < 0) - gui_hotlist_remove_buffer (buffer); + gui_hotlist_remove_buffer (buffer, 0); else (void) gui_hotlist_add (buffer, number, NULL); } @@ -2480,7 +2480,7 @@ gui_buffer_clear (struct t_gui_buffer *buffer) } } - gui_hotlist_remove_buffer (buffer); + gui_hotlist_remove_buffer (buffer, 0); gui_buffer_ask_chat_refresh (buffer, 2); @@ -2601,7 +2601,7 @@ gui_buffer_close (struct t_gui_buffer *buffer) } } - gui_hotlist_remove_buffer (buffer); + gui_hotlist_remove_buffer (buffer, 1); if (gui_hotlist_initial_buffer == buffer) gui_hotlist_initial_buffer = NULL; diff --git a/src/gui/gui-hotlist.c b/src/gui/gui-hotlist.c index aefad4a21..1a154ba0b 100644 --- a/src/gui/gui-hotlist.c +++ b/src/gui/gui-hotlist.c @@ -487,7 +487,8 @@ gui_hotlist_clear () */ void -gui_hotlist_remove_buffer (struct t_gui_buffer *buffer) +gui_hotlist_remove_buffer (struct t_gui_buffer *buffer, + int force_remove_buffer) { int hotlist_changed, hotlist_remove, buffer_to_remove; struct t_gui_hotlist *ptr_hotlist, *next_hotlist; @@ -504,19 +505,22 @@ gui_hotlist_remove_buffer (struct t_gui_buffer *buffer) { next_hotlist = ptr_hotlist->next_hotlist; - buffer_to_remove = 0; + buffer_to_remove = (force_remove_buffer) ? + (ptr_hotlist->buffer == buffer) : 0; + switch (hotlist_remove) { case CONFIG_LOOK_HOTLIST_REMOVE_BUFFER: - buffer_to_remove = (ptr_hotlist->buffer == buffer); + buffer_to_remove |= (ptr_hotlist->buffer == buffer); break; case CONFIG_LOOK_HOTLIST_REMOVE_MERGED: - buffer_to_remove = + buffer_to_remove |= ((ptr_hotlist->buffer->number == buffer->number) && (!ptr_hotlist->buffer->zoomed || (ptr_hotlist->buffer->active == 2))); break; } + if (buffer_to_remove) { gui_hotlist_free (&gui_hotlist, &last_gui_hotlist, ptr_hotlist); diff --git a/src/gui/gui-hotlist.h b/src/gui/gui-hotlist.h index 18cec9702..d53348823 100644 --- a/src/gui/gui-hotlist.h +++ b/src/gui/gui-hotlist.h @@ -59,7 +59,8 @@ extern struct t_gui_hotlist *gui_hotlist_add (struct t_gui_buffer *buffer, struct timeval *creation_time); extern void gui_hotlist_resort (); extern void gui_hotlist_clear (); -extern void gui_hotlist_remove_buffer (struct t_gui_buffer *buffer); +extern void gui_hotlist_remove_buffer (struct t_gui_buffer *buffer, + int force_remove_buffer); extern struct t_hdata *gui_hotlist_hdata_hotlist_cb (void *data, const char *hdata_name); extern int gui_hotlist_add_to_infolist (struct t_infolist *infolist, diff --git a/src/gui/gui-input.c b/src/gui/gui-input.c index 6e356da96..e7824dcd8 100644 --- a/src/gui/gui-input.c +++ b/src/gui/gui-input.c @@ -1383,7 +1383,7 @@ gui_input_jump_smart (struct t_gui_buffer *buffer) if (!gui_hotlist_initial_buffer) gui_hotlist_initial_buffer = window->buffer; gui_window_switch_to_buffer (window, gui_hotlist->buffer, 1); - gui_hotlist_remove_buffer (window->buffer); + gui_hotlist_remove_buffer (window->buffer, 0); scroll_to_bottom = 1; } else diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c index 425c16f36..bc6f556d8 100644 --- a/src/gui/gui-window.c +++ b/src/gui/gui-window.c @@ -1673,7 +1673,7 @@ gui_window_search_stop (struct t_gui_window *window) } window->scroll->start_line = NULL; window->scroll->start_line_pos = 0; - gui_hotlist_remove_buffer (window->buffer); + gui_hotlist_remove_buffer (window->buffer, 0); gui_buffer_ask_chat_refresh (window->buffer, 2); }