aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDr. David Alan Gilbert <dave@treblig.org>2017-05-14 17:58:45 +0100
committerDr. David Alan Gilbert <dave@treblig.org>2018-02-25 02:08:49 +0000
commitc155422e38306631c04dad430486b8a868af1921 (patch)
tree6fb0e5306e561c8a80a62a07f5767a2e01865197
parent21605558fa314518e6aae6f20f6728a746cfe320 (diff)
downloadpurple-matrix-c155422e38306631c04dad430486b8a868af1921.tar.gz
e2e: Cleanup inbound megolm sessions in memory
Cleanup on closing the plugin or leaving a conversation. Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
-rw-r--r--matrix-e2e.c45
-rw-r--r--matrix-e2e.h1
-rw-r--r--matrix-room.c1
3 files changed, 44 insertions, 3 deletions
diff --git a/matrix-e2e.c b/matrix-e2e.c
index a33176c..7337f2e 100644
--- a/matrix-e2e.c
+++ b/matrix-e2e.c
@@ -193,6 +193,23 @@ static guint megolm_inbound_hash(gconstpointer a)
g_str_hash(hk->device_id);
}
+static void megolm_inbound_key_destroy(gpointer v)
+{
+ MatrixHashKeyInBoundMegOlm *key = v;
+ g_free(key->sender_key);
+ g_free(key->session_id);
+ g_free(key->sender_id);
+ g_free(key->device_id);
+}
+
+static void megolm_inbound_value_destroy(gpointer v)
+{
+ OlmInboundGroupSession *oigs = v;
+
+ olm_clear_inbound_group_session(oigs);
+ g_free(oigs);
+}
+
static MatrixE2ERoomData *get_e2e_room_data(PurpleConversation *conv)
{
MatrixE2ERoomData *result;
@@ -211,9 +228,10 @@ static GHashTable *get_e2e_inbound_megolm_hash(PurpleConversation *conv)
MatrixE2ERoomData *rd = get_e2e_room_data(conv);
if (!rd->megolm_sessions_inbound) {
- // TODO: Handle deallocation
- rd->megolm_sessions_inbound = g_hash_table_new(megolm_inbound_hash,
- megolm_inbound_equality);
+ rd->megolm_sessions_inbound = g_hash_table_new_full(megolm_inbound_hash,
+ megolm_inbound_equality,
+ megolm_inbound_key_destroy,
+ megolm_inbound_value_destroy);
}
return rd->megolm_sessions_inbound;
@@ -1186,8 +1204,25 @@ out:
return ret;
}
+void matrix_e2e_cleanup_conversation(PurpleConversation *conv)
+{
+ MatrixE2ERoomData *result = purple_conversation_get_data(conv,
+ PURPLE_CONV_E2E_STATE);
+ if (result) {
+ g_hash_table_destroy(result->megolm_sessions_inbound);
+ g_free(result);
+ purple_conversation_set_data(conv, PURPLE_CONV_E2E_STATE, NULL);
+ }
+}
+
void matrix_e2e_cleanup_connection(MatrixConnectionData *conn)
{
+ GList *ptr;
+ for(ptr = purple_get_conversations(); ptr != NULL; ptr = g_list_next(ptr))
+ {
+ PurpleConversation *conv = ptr->data;
+ matrix_e2e_cleanup_conversation(conv);
+ }
if (conn->e2e) {
close_e2e_db(conn);
g_hash_table_destroy(conn->e2e->olm_session_hash);
@@ -1695,4 +1730,8 @@ void matrix_e2e_handle_sync_key_counts(PurpleConnection *pc, JsonObject *count_o
{
}
+void matrix_e2e_cleanup_conversation(PurpleConversation *conv)
+{
+}
+
#endif
diff --git a/matrix-e2e.h b/matrix-e2e.h
index a3d953f..3aaab9b 100644
--- a/matrix-e2e.h
+++ b/matrix-e2e.h
@@ -27,6 +27,7 @@ typedef struct _PurpleConversation PurpleConversation;
int matrix_e2e_get_device_keys(MatrixConnectionData *conn, const gchar *device_id);
void matrix_e2e_cleanup_connection(MatrixConnectionData *conn);
+void matrix_e2e_cleanup_conversation(PurpleConversation *conv);
void matrix_e2e_decrypt_d2d(struct _PurpleConnection *pc, struct _JsonObject *event);
JsonParser *matrix_e2e_decrypt_room(struct _PurpleConversation *conv, struct _JsonObject *event);
void matrix_e2e_handle_sync_key_counts(struct _PurpleConnection *pc, struct _JsonObject *count_object, gboolean force_send);
diff --git a/matrix-room.c b/matrix-room.c
index 60ab229..c9c8cde 100644
--- a/matrix-room.c
+++ b/matrix-room.c
@@ -1114,6 +1114,7 @@ void matrix_room_leave_chat(PurpleConversation *conv)
g_list_free_full(event_queue, (GDestroyNotify)matrix_event_free);
purple_conversation_set_data(conv, PURPLE_CONV_DATA_EVENT_QUEUE, NULL);
}
+ matrix_e2e_cleanup_conversation(conv);
}