From e3609b9ace07fe04eb2dfd6f6f2c6b3fb5a5d27f Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Sat, 20 Jul 2019 14:00:21 +0200 Subject: [PATCH] fix another memory leak in mainwindow when building the tree --- ncdc/src/mainwindow.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/ncdc/src/mainwindow.c b/ncdc/src/mainwindow.c index a00acd5..879c054 100644 --- a/ncdc/src/mainwindow.c +++ b/ncdc/src/mainwindow.c @@ -296,14 +296,10 @@ void ncdc_mainwindow_update_guilds(ncdc_mainwindow_t n) ncdc_treeitem_t i = ncdc_treeitem_new(); wchar_t *name = NULL; - if (i == NULL) { - continue; - } + goto_if_true(i == NULL, cleanup); name = s_convert(dc_guild_name(g)); - if (name == NULL) { - continue; - } + goto_if_true(i == NULL, cleanup); ncdc_treeitem_set_label(i, name); @@ -318,15 +314,12 @@ void ncdc_mainwindow_update_guilds(ncdc_mainwindow_t n) dc_channel_t c = dc_guild_nth_channel(g, idx); ncdc_treeitem_t ci = NULL; - if (dc_channel_name(c) == NULL || - dc_channel_id(c) == NULL) { - continue; - } + goto_if_true(dc_channel_name(c) == NULL || + dc_channel_id(c) == NULL, cleanup + ); ci = ncdc_treeitem_new(); - if (ci == NULL) { - continue; - } + goto_if_true(ci == NULL, cleanup); if (dc_channel_type(c) == CHANNEL_TYPE_GUILD_VOICE || dc_channel_type(c) == CHANNEL_TYPE_GUILD_TEXT) { @@ -338,7 +331,9 @@ void ncdc_mainwindow_update_guilds(ncdc_mainwindow_t n) } else { aswprintf(&name, L"%s", dc_channel_name(c)); } + if (name == NULL) { + dc_unref(ci); continue; } @@ -359,9 +354,20 @@ void ncdc_mainwindow_update_guilds(ncdc_mainwindow_t n) } else { ncdc_treeitem_add(i, ci); } + + dc_unref(ci); + ci = NULL; } ncdc_treeitem_add(n->root, i); + + cleanup: + + dc_unref(i); + i = NULL; + + free(name); + name = NULL; } g_hash_table_unref(parents);