From 0e0ffe4a83682bf40add43a665f475cfbc2b41c6 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Thu, 14 Apr 2016 17:59:17 +0200 Subject: [PATCH] Free messages exactly once --- structures.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/structures.c b/structures.c index 4b2fde04..9a2f7988 100644 --- a/structures.c +++ b/structures.c @@ -2570,11 +2570,22 @@ void tgls_free_message_gw (struct tgl_message *M, void *TLS) { tgls_free_message (TLS, M); } +void tgls_remove_message_gw (struct tgl_state *TLS, struct tgl_message *M) { + if (tree_lookup_message (TLS->message_unsent_tree, M)) { + tglm_message_remove_unsent (TLS, M); + } +} + +void tgls_remove_and_free_message_gw (struct tgl_message *M, void *TLS) { + tgls_remove_message_gw (TLS, M); + tgls_free_message (TLS, M); +} + void tgl_free_all (struct tgl_state *TLS) { tree_act_ex_peer (TLS->peer_tree, tgls_free_peer_gw, TLS); TLS->peer_tree = tree_clear_peer (TLS->peer_tree); TLS->peer_by_name_tree = tree_clear_peer_by_name (TLS->peer_by_name_tree); - tree_act_ex_message (TLS->message_tree, tgls_free_message_gw, TLS); + tree_act_ex_message (TLS->message_tree, tgls_remove_and_free_message_gw, TLS); TLS->message_tree = tree_clear_message (TLS->message_tree); tree_act_ex_message (TLS->message_unsent_tree, tgls_free_message_gw, TLS); TLS->message_unsent_tree = tree_clear_message (TLS->message_unsent_tree);