about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-07-04 14:25:53 +0200
committerMichael Vetter <jubalh@iodoru.org>2019-07-04 14:25:53 +0200
commit9aad2aa4878fffec098e8b2ecf382be565bd44a7 (patch)
tree9ea59b3c0a0475d1b4b02a339b36cd0133648640 /src
parent482138feff6a6de0fd3aacd7a00dd0f35a086d41 (diff)
downloadprofani-tty-9aad2aa4878fffec098e8b2ecf382be565bd44a7.tar.gz
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)
```
Diffstat (limited to 'src')
-rw-r--r--src/xmpp/iq.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 91acc212..e31f3269 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -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)
 {