talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit fc73942fc655111d25e097a02609c9ffa5cbf061
parent c771663a2ee1618348c8233ef6d465306b1136f2
Author: wwp <subscript@free.fr>
Date:   Sun, 26 Sep 2021 18:53:49 +0200

Fix CID 1491320, 1492199, 1492201: resource leaks.

Diffstat:
Msrc/toolbar.c | 44++++++++++++++++++++++++++++++++++----------
Msrc/toolbar.h | 8+++-----
2 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/src/toolbar.c b/src/toolbar.c @@ -479,10 +479,15 @@ static void toolbar_parse_item(XMLFile *file, ToolbarType source, gboolean *rewr attr = g_list_next(attr); } if (item->index != -1) { - if (!toolbar_is_duplicate(item->index, source)) + if (!toolbar_is_duplicate(item->index, source)) { toolbar_config[source].item_list = g_slist_append(toolbar_config[source].item_list, item); - } + } else { + toolbar_item_destroy(item); + } + } else { + toolbar_item_destroy(item); + } } const gchar *toolbar_get_short_text(int action) { @@ -636,10 +641,15 @@ static void toolbar_set_default_generic(ToolbarType toolbar_type, DefaultToolbar } if (toolbar_item->index != -1) { - if (!toolbar_is_duplicate(toolbar_item->index, toolbar_type)) + if (!toolbar_is_duplicate(toolbar_item->index, toolbar_type)) { toolbar_config[toolbar_type].item_list = g_slist_append(toolbar_config[toolbar_type].item_list, toolbar_item); - } + } else { + toolbar_item_destroy(toolbar_item); + } + } else { + toolbar_item_destroy(toolbar_item); + } } } @@ -765,10 +775,12 @@ void toolbar_save_config_file(ToolbarType source) fail: FILE_OP_ERROR(fileSpec, "fprintf"); - g_free( fileSpec ); + g_free(fileSpec); prefs_file_close_revert (pfile); - } else + } else { + g_free(fileSpec); g_warning("failed to open toolbar configuration file for writing"); + } } void toolbar_read_config_file(ToolbarType source) @@ -850,9 +862,7 @@ void toolbar_clear_list(ToolbarType source) toolbar_config[source].item_list = g_slist_remove(toolbar_config[source].item_list, item); - g_free(item->file); - g_free(item->text); - g_free(item); + toolbar_item_destroy(item); } g_slist_free(toolbar_config[source].item_list); } @@ -2645,7 +2655,8 @@ Toolbar *toolbar_create(ToolbarType type, #define UNREF_ICON(icon) if (toolbar->icon != NULL) \ g_object_unref(toolbar->icon) -void toolbar_destroy(Toolbar * toolbar) { +void toolbar_destroy(Toolbar * toolbar) +{ UNREF_ICON(compose_mail_icon); UNREF_ICON(compose_news_icon); UNREF_ICON(learn_spam_icon); @@ -2656,6 +2667,19 @@ void toolbar_destroy(Toolbar * toolbar) { #undef UNREF_ICON +void toolbar_item_destroy(ToolbarItem *item) +{ + cm_return_if_fail(item != NULL); + + if (item) { + if (item->file) \ + g_free(item->file); \ + if (item->text) \ + g_free(item->text); \ + g_free(item);\ + } +} + void toolbar_update(ToolbarType type, gpointer data) { Toolbar *toolbar_data; diff --git a/src/toolbar.h b/src/toolbar.h @@ -127,11 +127,7 @@ struct _ToolbarItem { while (item_list != NULL) { \ item = (ToolbarItem*)item_list->data; \ item_list = g_slist_remove(item_list, item); \ - if (item->file) \ - g_free(item->file); \ - if (item->text) \ - g_free(item->text); \ - g_free(item);\ + toolbar_item_destroy(item); \ }\ g_slist_free(item_list);\ } @@ -282,6 +278,8 @@ void toolbar_set_style (GtkWidget *toolbar_wid, GtkWidget *handlebox_wid, guint action); void toolbar_destroy (Toolbar *toolbar); +void toolbar_item_destroy (ToolbarItem *toolbar_item); + void toolbar_set_learn_button (Toolbar *toolbar, LearnButtonType learn_btn_type); const gchar *toolbar_get_short_text (int action);