From 1bca8e52ac5e6713c26867195fffed2e49861f0e Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Sun, 14 Nov 2010 23:11:40 +0100 Subject: [PATCH] Memleak: free the XMPP-Eventqueue on shutdown TODO: the event_jid member contains an unclean pointer, no clue why. --- citadel/modules/xmpp/serv_xmpp.c | 4 +++- citadel/modules/xmpp/xmpp_queue.c | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/citadel/modules/xmpp/serv_xmpp.c b/citadel/modules/xmpp/serv_xmpp.c index 5015c3184..922288f69 100644 --- a/citadel/modules/xmpp/serv_xmpp.c +++ b/citadel/modules/xmpp/serv_xmpp.c @@ -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 */ diff --git a/citadel/modules/xmpp/xmpp_queue.c b/citadel/modules/xmpp/xmpp_queue.c index 811f26452..986cb2570 100644 --- a/citadel/modules/xmpp/xmpp_queue.c +++ b/citadel/modules/xmpp/xmpp_queue.c @@ -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); + +} -- 2.30.2