commit 51309b73b0c9222b8c1dc8f20adc921433e706cd
parent 8641d0af12d460e251924ab1b1e1549825911833
Author: Jacki <jacki@thejackimonster.de>
Date: Sun, 21 Jan 2024 04:59:10 +0100
Fix two memory leaks
Signed-off-by: Jacki <jacki@thejackimonster.de>
Diffstat:
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c
@@ -124,5 +124,8 @@ contact_destroy (struct GNUNET_CHAT_Contact* contact)
if (contact->public_key)
GNUNET_free(contact->public_key);
+ if ((contact->context) && (!contact->context->room))
+ context_destroy(contact->context);
+
GNUNET_free(contact);
}
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
@@ -881,10 +881,11 @@ GNUNET_CHAT_contact_get_context (struct GNUNET_CHAT_Contact *contact)
struct GNUNET_CHAT_Context *context = contact_find_context(contact);
if ((context) && (GNUNET_CHAT_CONTEXT_TYPE_CONTACT == context->type))
- return context;
+ goto attach_return;
context = context_create_from_contact(contact->handle, contact->member);
+attach_return:
if (context)
contact->context = context;
@@ -1216,23 +1217,29 @@ GNUNET_CHAT_context_request (struct GNUNET_CHAT_Context *context)
struct GNUNET_CHAT_Context *other = contact_find_context(contact);
if ((!other) || (!(other->room)))
- return;
+ goto cleanup_contact;
struct GNUNET_HashCode key;
GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, &key, sizeof(key));
if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(
handle->contexts, &key))
- return;
+ goto cleanup_contact;
struct GNUNET_MESSENGER_Room *room = GNUNET_MESSENGER_open_room(
handle->messenger, &key
);
if (!room)
- return;
+ goto cleanup_contact;
context_update_room(context, room);
+
+ if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(
+ handle->contexts, &key, context,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
+ goto cleanup_room;
+
handle_send_room_name(handle, room);
struct GNUNET_MESSENGER_Message msg;
@@ -1241,6 +1248,13 @@ GNUNET_CHAT_context_request (struct GNUNET_CHAT_Context *context)
GNUNET_memcpy(&(msg.body.invite.key), &key, sizeof(msg.body.invite.key));
GNUNET_MESSENGER_send_message(other->room, &msg, context->contact);
+ return;
+
+cleanup_room:
+ GNUNET_MESSENGER_close_room(room);
+
+cleanup_contact:
+ contact_destroy(contact);
}