fix another memory leak in mainwindow when building the tree

This commit is contained in:
Florian Stinglmayr 2019-07-20 14:00:21 +02:00
parent 08b69263d6
commit e3609b9ace

View File

@ -296,14 +296,10 @@ void ncdc_mainwindow_update_guilds(ncdc_mainwindow_t n)
ncdc_treeitem_t i = ncdc_treeitem_new(); ncdc_treeitem_t i = ncdc_treeitem_new();
wchar_t *name = NULL; wchar_t *name = NULL;
if (i == NULL) { goto_if_true(i == NULL, cleanup);
continue;
}
name = s_convert(dc_guild_name(g)); name = s_convert(dc_guild_name(g));
if (name == NULL) { goto_if_true(i == NULL, cleanup);
continue;
}
ncdc_treeitem_set_label(i, name); 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); dc_channel_t c = dc_guild_nth_channel(g, idx);
ncdc_treeitem_t ci = NULL; ncdc_treeitem_t ci = NULL;
if (dc_channel_name(c) == NULL || goto_if_true(dc_channel_name(c) == NULL ||
dc_channel_id(c) == NULL) { dc_channel_id(c) == NULL, cleanup
continue; );
}
ci = ncdc_treeitem_new(); ci = ncdc_treeitem_new();
if (ci == NULL) { goto_if_true(ci == NULL, cleanup);
continue;
}
if (dc_channel_type(c) == CHANNEL_TYPE_GUILD_VOICE || if (dc_channel_type(c) == CHANNEL_TYPE_GUILD_VOICE ||
dc_channel_type(c) == CHANNEL_TYPE_GUILD_TEXT) { dc_channel_type(c) == CHANNEL_TYPE_GUILD_TEXT) {
@ -338,7 +331,9 @@ void ncdc_mainwindow_update_guilds(ncdc_mainwindow_t n)
} else { } else {
aswprintf(&name, L"%s", dc_channel_name(c)); aswprintf(&name, L"%s", dc_channel_name(c));
} }
if (name == NULL) { if (name == NULL) {
dc_unref(ci);
continue; continue;
} }
@ -359,9 +354,20 @@ void ncdc_mainwindow_update_guilds(ncdc_mainwindow_t n)
} else { } else {
ncdc_treeitem_add(i, ci); ncdc_treeitem_add(i, ci);
} }
dc_unref(ci);
ci = NULL;
} }
ncdc_treeitem_add(n->root, i); ncdc_treeitem_add(n->root, i);
cleanup:
dc_unref(i);
i = NULL;
free(name);
name = NULL;
} }
g_hash_table_unref(parents); g_hash_table_unref(parents);