1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Free iq_id_handlers correctly

so far only the key part was freed. We also need to free the actual
handler.

Fix:
```
==21171== 1,128 bytes in 47 blocks are definitely lost in loss record
3,476 of 3,670
==21171==    at 0x483677F: malloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21171==    by 0x434248: iq_id_handler_add (iq.c:265)
==21171==    by 0x4B122E: omemo_devicelist_request (omemo.c:46)
==21171==    by 0x4AC411: omemo_start_session (omemo.c:409)
==21171==    by 0x4AC37C: omemo_start_sessions (omemo.c:396)
==21171==    by 0x447881: sv_ev_roster_received (server_events.c:189)
==21171==    by 0x444019: roster_result_handler (roster.c:312)
==21171==    by 0x433FC2: _iq_handler (iq.c:202)
==21171==    by 0x5AF118E: ??? (in /usr/lib64/libmesode.so.0.0.0)
==21171==    by 0x5AEDBDA: ??? (in /usr/lib64/libmesode.so.0.0.0)
==21171==    by 0x5AFA43E: ??? (in /usr/lib64/libmesode.so.0.0.0)
==21171==    by 0x6818AA4: ??? (in /usr/lib64/libexpat.so.1.6.8)
==21171==    by 0x681A3AB: ??? (in /usr/lib64/libexpat.so.1.6.8)
==21171==    by 0x681D7EB: XML_ParseBuffer (in
/usr/lib64/libexpat.so.1.6.8)
==21171==    by 0x5AF0A63: xmpp_run_once (in
/usr/lib64/libmesode.so.0.0.0)
==21171==    by 0x432E5D: connection_check_events (connection.c:104)
==21171==    by 0x4323B3: session_process_events (session.c:255)
==21171==    by 0x42C097: prof_run (profanity.c:128)
==21171==    by 0x4B2627: main (main.c:172)
```
This commit is contained in:
Michael Vetter 2019-07-04 14:25:53 +02:00
parent 482138feff
commit 9aad2aa487

View File

@ -134,6 +134,7 @@ static int _command_exec_response_handler(xmpp_stanza_t *const stanza, void *con
static void _iq_free_room_data(ProfRoomInfoData *roominfo);
static void _iq_free_affiliation_set(ProfPrivilegeSet *affiliation_set);
static void _iq_id_handler_free(ProfIqHandler *handler);
// scheduled
static int _autoping_timed_send(xmpp_conn_t *const conn, void *const userdata);
@ -247,7 +248,7 @@ iq_handlers_init(void)
g_list_free(keys);
g_hash_table_destroy(id_handlers);
}
id_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
id_handlers = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_iq_id_handler_free);
rooms_cache = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)xmpp_stanza_release);
}
@ -259,6 +260,19 @@ iq_handlers_clear()
}
}
static void
_iq_id_handler_free(ProfIqHandler *handler)
{
if (handler == NULL) {
return;
}
if (handler->free_func && handler->userdata) {
handler->free_func(handler->userdata);
}
free(handler);
handler = NULL;
}
void
iq_id_handler_add(const char *const id, ProfIqCallback func, ProfIqFreeCallback free_func, void *userdata)
{