about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-06-19 23:49:04 +0200
committerMichael Vetter <jubalh@iodoru.org>2019-06-20 12:37:32 +0200
commitb8c8059402d923814e6d82d9d32b3c6b3236b0ff (patch)
treeb5fda86c249412992aec53613bb2175ac8a051f3 /src
parent11b8204d14af3777fe6c4083988ea8681354cb1c (diff)
downloadprofani-tty-b8c8059402d923814e6d82d9d32b3c6b3236b0ff.tar.gz
Call message_handlers_clear() upon disconnect
Free pubsub_event_handlers. Fix memory leaks.
Diffstat (limited to 'src')
-rw-r--r--src/xmpp/message.c8
-rw-r--r--src/xmpp/message.h1
-rw-r--r--src/xmpp/session.c1
3 files changed, 10 insertions, 0 deletions
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
@@ -179,6 +179,14 @@ message_handlers_init(void)
 }
 
 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)
 {
     ProfMessageHandler *handler = malloc(sizeof(ProfMessageHandler));
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();