aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-01-09 23:49:07 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-01-09 23:49:07 +0100
commit5d649fb886893d2ab393473188854add22114d0c (patch)
tree4fb67848a813d0245ee2f662ac125aaa9ded8fc7
parent87ead322b24027dae30b603db86c71d7d819dda3 (diff)
downloadlibgnunetchat-5d649fb886893d2ab393473188854add22114d0c.tar.gz
libgnunetchat-5d649fb886893d2ab393473188854add22114d0c.zip
Fixed too early deallocation of internal messages
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/gnunet_chat_handle.c41
-rw-r--r--src/gnunet_chat_handle.h12
2 files changed, 49 insertions, 4 deletions
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
index ff7e210..a4be709 100644
--- a/src/gnunet_chat_handle.c
+++ b/src/gnunet_chat_handle.c
@@ -42,6 +42,9 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg,
42 on_handle_shutdown, handle 42 on_handle_shutdown, handle
43 ); 43 );
44 44
45 handle->internal_head = NULL;
46 handle->internal_tail = NULL;
47
45 if ((directory) && 48 if ((directory) &&
46 (GNUNET_YES == GNUNET_DISK_directory_test(directory, GNUNET_YES))) 49 (GNUNET_YES == GNUNET_DISK_directory_test(directory, GNUNET_YES)))
47 handle->directory = GNUNET_strdup(directory); 50 handle->directory = GNUNET_strdup(directory);
@@ -162,6 +165,23 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle)
162 if (handle->directory) 165 if (handle->directory)
163 GNUNET_free(handle->directory); 166 GNUNET_free(handle->directory);
164 167
168 struct GNUNET_CHAT_InternalMessages *internal;
169 while (handle->internal_head)
170 {
171 internal = handle->internal_head;
172
173 if (internal->msg)
174 message_destroy(internal->msg);
175
176 GNUNET_CONTAINER_DLL_remove(
177 handle->internal_head,
178 handle->internal_tail,
179 internal
180 );
181
182 GNUNET_free(internal);
183 }
184
165 GNUNET_free(handle); 185 GNUNET_free(handle);
166} 186}
167 187
@@ -176,12 +196,27 @@ handle_send_internal_message (struct GNUNET_CHAT_Handle *handle,
176 if (!(handle->msg_cb)) 196 if (!(handle->msg_cb))
177 return; 197 return;
178 198
179 struct GNUNET_CHAT_Message *msg = message_create_internally( 199 struct GNUNET_CHAT_InternalMessages *internal = GNUNET_new(
200 struct GNUNET_CHAT_InternalMessages
201 );
202
203 internal->msg = message_create_internally(
180 context, flag, warning 204 context, flag, warning
181 ); 205 );
182 206
183 handle->msg_cb(handle->msg_cls, context, msg); 207 if (!(internal->msg))
184 message_destroy(msg); 208 {
209 GNUNET_free(internal);
210 return;
211 }
212
213 handle->msg_cb(handle->msg_cls, context, internal->msg);
214
215 GNUNET_CONTAINER_DLL_insert(
216 handle->internal_head,
217 handle->internal_tail,
218 internal
219 );
185} 220}
186 221
187void 222void
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
index 5faa2da..90cbd8a 100644
--- a/src/gnunet_chat_handle.h
+++ b/src/gnunet_chat_handle.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021--2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -38,11 +38,21 @@
38#include "gnunet_chat_lib.h" 38#include "gnunet_chat_lib.h"
39#include "gnunet_chat_message.h" 39#include "gnunet_chat_message.h"
40 40
41struct GNUNET_CHAT_InternalMessages
42{
43 struct GNUNET_CHAT_Message *msg;
44 struct GNUNET_CHAT_InternalMessages *next;
45 struct GNUNET_CHAT_InternalMessages *prev;
46};
47
41struct GNUNET_CHAT_Handle 48struct GNUNET_CHAT_Handle
42{ 49{
43 const struct GNUNET_CONFIGURATION_Handle* cfg; 50 const struct GNUNET_CONFIGURATION_Handle* cfg;
44 struct GNUNET_SCHEDULER_Task *shutdown_hook; 51 struct GNUNET_SCHEDULER_Task *shutdown_hook;
45 52
53 struct GNUNET_CHAT_InternalMessages *internal_head;
54 struct GNUNET_CHAT_InternalMessages *internal_tail;
55
46 char *directory; 56 char *directory;
47 57
48 GNUNET_CHAT_ContextMessageCallback msg_cb; 58 GNUNET_CHAT_ContextMessageCallback msg_cb;