From b8c8059402d923814e6d82d9d32b3c6b3236b0ff Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 19 Jun 2019 23:49:04 +0200 Subject: [PATCH] Call message_handlers_clear() upon disconnect Free pubsub_event_handlers. Fix memory leaks. --- src/xmpp/message.c | 8 ++++++++ src/xmpp/message.h | 1 + src/xmpp/session.c | 1 + 3 files changed, 10 insertions(+) diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 47cf35d7..9f0ffb2b 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -178,6 +178,14 @@ message_handlers_init(void) pubsub_event_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, free, free); } +void +message_handlers_clear(void) +{ + if (pubsub_event_handlers) { + g_hash_table_remove_all(pubsub_event_handlers); + } +} + void message_pubsub_event_handler_add(const char *const node, ProfMessageCallback func, ProfMessageFreeCallback free_func, void *userdata) { diff --git a/src/xmpp/message.h b/src/xmpp/message.h index 0c81ca39..a42644fd 100644 --- a/src/xmpp/message.h +++ b/src/xmpp/message.h @@ -39,6 +39,7 @@ typedef int(*ProfMessageCallback)(xmpp_stanza_t *const stanza, void *const userd typedef void(*ProfMessageFreeCallback)(void *userdata); void message_handlers_init(void); +void message_handlers_clear(void); void message_pubsub_event_handler_add(const char *const node, ProfMessageCallback func, ProfMessageFreeCallback free_func, void *userdata); #endif diff --git a/src/xmpp/session.c b/src/xmpp/session.c index 787dc0b3..1d873012 100644 --- a/src/xmpp/session.c +++ b/src/xmpp/session.c @@ -216,6 +216,7 @@ session_disconnect(void) iq_handlers_clear(); connection_disconnect(); + message_handlers_clear(); connection_clear_data(); chat_sessions_clear();