diff --git a/src/core/wee-hdata.c b/src/core/wee-hdata.c index f6fa214a1..be5bc4d6a 100644 --- a/src/core/wee-hdata.c +++ b/src/core/wee-hdata.c @@ -1062,6 +1062,9 @@ hdata_get_string (struct t_hdata *hdata, const char *property) void hdata_free (struct t_hdata *hdata) { + if (!hdata) + return; + if (hdata->hash_var) hashtable_free (hdata->hash_var); if (hdata->var_prev) diff --git a/src/core/wee-infolist.c b/src/core/wee-infolist.c index 070cd685c..99678cfbb 100644 --- a/src/core/wee-infolist.c +++ b/src/core/wee-infolist.c @@ -584,6 +584,9 @@ infolist_var_free (struct t_infolist_item *item, { struct t_infolist_var *new_vars; + if (!item || !var) + return; + /* remove var */ if (item->last_var == var) item->last_var = var->prev_var; @@ -625,6 +628,9 @@ infolist_item_free (struct t_infolist *infolist, { struct t_infolist_item *new_items; + if (!infolist || !item) + return; + /* remove var */ if (infolist->last_item == item) infolist->last_item = item->prev_item; @@ -661,6 +667,9 @@ infolist_free (struct t_infolist *infolist) { struct t_infolist *new_weechat_infolists; + if (!infolist) + return; + /* remove list */ if (last_weechat_infolist == infolist) last_weechat_infolist = infolist->prev_infolist; diff --git a/src/core/wee-string.c b/src/core/wee-string.c index b652abf14..3003bcf8b 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -3184,6 +3184,9 @@ string_shared_free (const char *string) { string_shared_count_t *ptr_count; + if (!string) + return; + ptr_count = (string_shared_count_t *)(string - sizeof (string_shared_count_t)); (*ptr_count)--; diff --git a/src/gui/curses/gui-curses-window.c b/src/gui/curses/gui-curses-window.c index 05bd4e407..bda0b7e10 100644 --- a/src/gui/curses/gui-curses-window.c +++ b/src/gui/curses/gui-curses-window.c @@ -146,6 +146,9 @@ gui_window_objects_init (struct t_gui_window *window) void gui_window_objects_free (struct t_gui_window *window, int free_separators) { + if (!window) + return; + if (GUI_WINDOW_OBJECTS(window)->win_chat) { delwin (GUI_WINDOW_OBJECTS(window)->win_chat); diff --git a/src/gui/gui-color.c b/src/gui/gui-color.c index 747fb840e..fcfb2a9bd 100644 --- a/src/gui/gui-color.c +++ b/src/gui/gui-color.c @@ -1147,13 +1147,13 @@ gui_color_emphasize (const char *string, void gui_color_free (struct t_gui_color *color) { - if (color) - { - if (color->string) - free (color->string); + if (!color) + return; - free (color); - } + if (color->string) + free (color->string); + + free (color); } /* diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index 9b6a12242..d5ece75fe 100644 --- a/src/gui/gui-completion.c +++ b/src/gui/gui-completion.c @@ -200,7 +200,11 @@ gui_completion_free_data (struct t_gui_completion *completion) void gui_completion_free (struct t_gui_completion *completion) { + if (!completion) + return; + gui_completion_free_data (completion); + free (completion); } diff --git a/src/gui/gui-filter.c b/src/gui/gui-filter.c index 3b50f1922..e32f2be4a 100644 --- a/src/gui/gui-filter.c +++ b/src/gui/gui-filter.c @@ -467,6 +467,9 @@ gui_filter_free (struct t_gui_filter *filter) { int i; + if (!filter) + return; + (void) hook_signal_send ("filter_removing", WEECHAT_HOOK_SIGNAL_POINTER, filter); diff --git a/src/gui/gui-history.c b/src/gui/gui-history.c index 8fbf4583a..2eaaf68d8 100644 --- a/src/gui/gui-history.c +++ b/src/gui/gui-history.c @@ -201,6 +201,9 @@ gui_history_buffer_free (struct t_gui_buffer *buffer) { struct t_gui_history *ptr_history; + if (!buffer) + return; + while (buffer->history) { ptr_history = buffer->history->next_history; diff --git a/src/gui/gui-hotlist.c b/src/gui/gui-hotlist.c index c7cc1700d..9bbcf65e0 100644 --- a/src/gui/gui-hotlist.c +++ b/src/gui/gui-hotlist.c @@ -96,6 +96,9 @@ gui_hotlist_free (struct t_gui_hotlist **hotlist, { struct t_gui_hotlist *new_hotlist; + if (!ptr_hotlist) + return; + /* remove hotlist from queue */ if (*last_hotlist == ptr_hotlist) *last_hotlist = ptr_hotlist->prev_hotlist; diff --git a/src/gui/gui-key.c b/src/gui/gui-key.c index 8da3bb666..e7255fb96 100644 --- a/src/gui/gui-key.c +++ b/src/gui/gui-key.c @@ -1435,6 +1435,9 @@ gui_key_free (struct t_gui_key **keys, struct t_gui_key **last_key, { int i; + if (!key) + return; + /* free memory */ if (key->key) free (key->key); diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c index 70296d0c7..63cfa6523 100644 --- a/src/gui/gui-line.c +++ b/src/gui/gui-line.c @@ -83,6 +83,9 @@ gui_lines_alloc () void gui_lines_free (struct t_gui_lines *lines) { + if (!lines) + return; + free (lines); } @@ -112,6 +115,9 @@ gui_line_tags_alloc (struct t_gui_line_data *line_data, const char *tags) void gui_line_tags_free (struct t_gui_line_data *line_data) { + if (!line_data) + return; + if (line_data->tags_array) { string_free_split_shared (line_data->tags_array); @@ -1120,6 +1126,9 @@ gui_line_free (struct t_gui_buffer *buffer, struct t_gui_line *line) { struct t_gui_line *ptr_line; + if (!buffer || !line) + return; + /* first remove mixed line if it exists */ if (buffer->mixed_lines) { diff --git a/src/gui/gui-window.c b/src/gui/gui-window.c index 5713125b1..f3aaafc31 100644 --- a/src/gui/gui-window.c +++ b/src/gui/gui-window.c @@ -332,15 +332,16 @@ gui_window_tree_node_to_leaf (struct t_gui_window_tree *node, void gui_window_tree_free (struct t_gui_window_tree **tree) { - if (*tree) - { - if ((*tree)->child1) - gui_window_tree_free (&((*tree)->child1)); - if ((*tree)->child2) - gui_window_tree_free (&((*tree)->child2)); - free (*tree); - *tree = NULL; - } + if (!tree || !*tree) + return; + + if ((*tree)->child1) + gui_window_tree_free (&((*tree)->child1)); + if ((*tree)->child2) + gui_window_tree_free (&((*tree)->child2)); + + free (*tree); + *tree = NULL; } /* @@ -418,6 +419,9 @@ void gui_window_scroll_free (struct t_gui_window *window, struct t_gui_window_scroll *scroll) { + if (!window || !scroll) + return; + if (scroll->prev_scroll) (scroll->prev_scroll)->next_scroll = scroll->next_scroll; if (scroll->next_scroll)