libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit 5d649fb886893d2ab393473188854add22114d0c
parent 87ead322b24027dae30b603db86c71d7d819dda3
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Sun,  9 Jan 2022 23:49:07 +0100

Fixed too early deallocation of internal messages

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>

Diffstat:
Msrc/gnunet_chat_handle.c | 41++++++++++++++++++++++++++++++++++++++---
Msrc/gnunet_chat_handle.h | 12+++++++++++-
2 files changed, 49 insertions(+), 4 deletions(-)

diff --git 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, on_handle_shutdown, handle ); + handle->internal_head = NULL; + handle->internal_tail = NULL; + if ((directory) && (GNUNET_YES == GNUNET_DISK_directory_test(directory, GNUNET_YES))) handle->directory = GNUNET_strdup(directory); @@ -162,6 +165,23 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle) if (handle->directory) GNUNET_free(handle->directory); + struct GNUNET_CHAT_InternalMessages *internal; + while (handle->internal_head) + { + internal = handle->internal_head; + + if (internal->msg) + message_destroy(internal->msg); + + GNUNET_CONTAINER_DLL_remove( + handle->internal_head, + handle->internal_tail, + internal + ); + + GNUNET_free(internal); + } + GNUNET_free(handle); } @@ -176,12 +196,27 @@ handle_send_internal_message (struct GNUNET_CHAT_Handle *handle, if (!(handle->msg_cb)) return; - struct GNUNET_CHAT_Message *msg = message_create_internally( + struct GNUNET_CHAT_InternalMessages *internal = GNUNET_new( + struct GNUNET_CHAT_InternalMessages + ); + + internal->msg = message_create_internally( context, flag, warning ); - handle->msg_cb(handle->msg_cls, context, msg); - message_destroy(msg); + if (!(internal->msg)) + { + GNUNET_free(internal); + return; + } + + handle->msg_cb(handle->msg_cls, context, internal->msg); + + GNUNET_CONTAINER_DLL_insert( + handle->internal_head, + handle->internal_tail, + internal + ); } void diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2021 GNUnet e.V. + Copyright (C) 2021--2022 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -38,11 +38,21 @@ #include "gnunet_chat_lib.h" #include "gnunet_chat_message.h" +struct GNUNET_CHAT_InternalMessages +{ + struct GNUNET_CHAT_Message *msg; + struct GNUNET_CHAT_InternalMessages *next; + struct GNUNET_CHAT_InternalMessages *prev; +}; + struct GNUNET_CHAT_Handle { const struct GNUNET_CONFIGURATION_Handle* cfg; struct GNUNET_SCHEDULER_Task *shutdown_hook; + struct GNUNET_CHAT_InternalMessages *internal_head; + struct GNUNET_CHAT_InternalMessages *internal_tail; + char *directory; GNUNET_CHAT_ContextMessageCallback msg_cb;