Memleak: free the XMPP-Eventqueue on shutdown
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 14 Nov 2010 22:11:40 +0000 (23:11 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 14 Nov 2010 22:11:40 +0000 (23:11 +0100)
 TODO: the event_jid member contains an unclean pointer, no clue why.

citadel/modules/xmpp/serv_xmpp.c
citadel/modules/xmpp/xmpp_queue.c

index 5015c3184267b70a26f98364bbaf013efefc8195..922288f695bed26f71e7f404d2c15d9da2042098 100644 (file)
@@ -580,7 +580,7 @@ void xmpp_logout_hook(void) {
 
 
 const char *CitadelServiceXMPP="XMPP";
-
+extern void xmpp_cleanup_events(void);
 CTDL_MODULE_INIT(xmpp)
 {
        if (!threading) {
@@ -596,6 +596,8 @@ CTDL_MODULE_INIT(xmpp)
                 CtdlRegisterSessionHook(xmpp_logout_hook, EVT_LOGOUT);
                 CtdlRegisterSessionHook(xmpp_login_hook, EVT_UNSTEALTH);
                 CtdlRegisterSessionHook(xmpp_logout_hook, EVT_STEALTH);
+               CtdlRegisterCleanupHook(xmpp_cleanup_events);
+
        }
 
        /* return our Subversion id for the Log */
index 811f2645230ea37b3f1af3359aa321b362c0c0fd..986cb2570b5e10b9af61dfce7146153c0c092bfc 100644 (file)
@@ -146,3 +146,24 @@ void xmpp_process_events(void) {
 
        XMPP->last_event_processed = highest_event;
 }
+
+
+void xmpp_cleanup_events(void)
+{
+        struct xmpp_event *ptr, *ptr2;
+        begin_critical_section(S_XMPP_QUEUE);
+       ptr = xmpp_queue;
+       xmpp_queue = NULL;
+       while (ptr != NULL) {
+#if 0
+// TODO: why do we have an invalid pointer here?
+               if (ptr->event_jid != NULL)
+                       free(ptr->event_jid);
+#endif
+               ptr2 = ptr->next;
+               free(ptr);
+               ptr = ptr2;
+       }
+        end_critical_section(S_XMPP_QUEUE);
+
+}