diff options
author | Jacki <jacki@thejackimonster.de> | 2024-01-21 04:59:10 +0100 |
---|---|---|
committer | Jacki <jacki@thejackimonster.de> | 2024-01-21 04:59:10 +0100 |
commit | 51309b73b0c9222b8c1dc8f20adc921433e706cd (patch) | |
tree | 96a2aaa0f8787aac51ea4959ae1254bf3b11a7df | |
parent | 8641d0af12d460e251924ab1b1e1549825911833 (diff) | |
download | libgnunetchat-51309b73b0c9222b8c1dc8f20adc921433e706cd.tar.gz libgnunetchat-51309b73b0c9222b8c1dc8f20adc921433e706cd.zip |
Fix two memory leaks
Signed-off-by: Jacki <jacki@thejackimonster.de>
-rw-r--r-- | src/gnunet_chat_contact.c | 3 | ||||
-rw-r--r-- | src/gnunet_chat_lib.c | 22 |
2 files changed, 21 insertions, 4 deletions
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c index bde6669..f3bf2dc 100644 --- a/src/gnunet_chat_contact.c +++ b/src/gnunet_chat_contact.c | |||
@@ -124,5 +124,8 @@ contact_destroy (struct GNUNET_CHAT_Contact* contact) | |||
124 | if (contact->public_key) | 124 | if (contact->public_key) |
125 | GNUNET_free(contact->public_key); | 125 | GNUNET_free(contact->public_key); |
126 | 126 | ||
127 | if ((contact->context) && (!contact->context->room)) | ||
128 | context_destroy(contact->context); | ||
129 | |||
127 | GNUNET_free(contact); | 130 | GNUNET_free(contact); |
128 | } | 131 | } |
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c index 0310f55..3010ff4 100644 --- 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) | |||
881 | struct GNUNET_CHAT_Context *context = contact_find_context(contact); | 881 | struct GNUNET_CHAT_Context *context = contact_find_context(contact); |
882 | 882 | ||
883 | if ((context) && (GNUNET_CHAT_CONTEXT_TYPE_CONTACT == context->type)) | 883 | if ((context) && (GNUNET_CHAT_CONTEXT_TYPE_CONTACT == context->type)) |
884 | return context; | 884 | goto attach_return; |
885 | 885 | ||
886 | context = context_create_from_contact(contact->handle, contact->member); | 886 | context = context_create_from_contact(contact->handle, contact->member); |
887 | 887 | ||
888 | attach_return: | ||
888 | if (context) | 889 | if (context) |
889 | contact->context = context; | 890 | contact->context = context; |
890 | 891 | ||
@@ -1216,23 +1217,29 @@ GNUNET_CHAT_context_request (struct GNUNET_CHAT_Context *context) | |||
1216 | struct GNUNET_CHAT_Context *other = contact_find_context(contact); | 1217 | struct GNUNET_CHAT_Context *other = contact_find_context(contact); |
1217 | 1218 | ||
1218 | if ((!other) || (!(other->room))) | 1219 | if ((!other) || (!(other->room))) |
1219 | return; | 1220 | goto cleanup_contact; |
1220 | 1221 | ||
1221 | struct GNUNET_HashCode key; | 1222 | struct GNUNET_HashCode key; |
1222 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, &key, sizeof(key)); | 1223 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, &key, sizeof(key)); |
1223 | 1224 | ||
1224 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains( | 1225 | if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains( |
1225 | handle->contexts, &key)) | 1226 | handle->contexts, &key)) |
1226 | return; | 1227 | goto cleanup_contact; |
1227 | 1228 | ||
1228 | struct GNUNET_MESSENGER_Room *room = GNUNET_MESSENGER_open_room( | 1229 | struct GNUNET_MESSENGER_Room *room = GNUNET_MESSENGER_open_room( |
1229 | handle->messenger, &key | 1230 | handle->messenger, &key |
1230 | ); | 1231 | ); |
1231 | 1232 | ||
1232 | if (!room) | 1233 | if (!room) |
1233 | return; | 1234 | goto cleanup_contact; |
1234 | 1235 | ||
1235 | context_update_room(context, room); | 1236 | context_update_room(context, room); |
1237 | |||
1238 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | ||
1239 | handle->contexts, &key, context, | ||
1240 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
1241 | goto cleanup_room; | ||
1242 | |||
1236 | handle_send_room_name(handle, room); | 1243 | handle_send_room_name(handle, room); |
1237 | 1244 | ||
1238 | struct GNUNET_MESSENGER_Message msg; | 1245 | struct GNUNET_MESSENGER_Message msg; |
@@ -1241,6 +1248,13 @@ GNUNET_CHAT_context_request (struct GNUNET_CHAT_Context *context) | |||
1241 | GNUNET_memcpy(&(msg.body.invite.key), &key, sizeof(msg.body.invite.key)); | 1248 | GNUNET_memcpy(&(msg.body.invite.key), &key, sizeof(msg.body.invite.key)); |
1242 | 1249 | ||
1243 | GNUNET_MESSENGER_send_message(other->room, &msg, context->contact); | 1250 | GNUNET_MESSENGER_send_message(other->room, &msg, context->contact); |
1251 | return; | ||
1252 | |||
1253 | cleanup_room: | ||
1254 | GNUNET_MESSENGER_close_room(room); | ||
1255 | |||
1256 | cleanup_contact: | ||
1257 | contact_destroy(contact); | ||
1244 | } | 1258 | } |
1245 | 1259 | ||
1246 | 1260 | ||