From cc793e134aba328abbb267138163293f67454dd9 Mon Sep 17 00:00:00 2001 From: Dane MacFadden Date: Sat, 26 Sep 2026 13:04:54 -0600 Subject: [PATCH] Added list to store history of messages. This is done to address a memory leak. Each thread allocates another 512 bytes and never frees it, but the program breaks if it is freed. Storing a copy of the messages in this list will allow each message stored to be trimmed to its actual size and not 512 bytes, and then the original message can be freed. At the end of execution, the list can be freed. --- main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.c b/main.c index 5d45352..b73d320 100644 --- a/main.c +++ b/main.c @@ -210,6 +210,7 @@ void *output(void *arg) { pthread_mutex_lock(&context->mut_render); notcurses_render(context->ctx_nc); pthread_mutex_unlock(&context->mut_render); + } return 0; } @@ -236,7 +237,7 @@ int main(int argc, char* argv[]) { int yes = 1; /* threading stuff */ - LIST *receivelist, *sendlist; + LIST *receivelist, *sendlist, *history; pthread_t input_thread, send_thread, receive_thread, output_thread; pthread_mutex_t sendmut, receivemut, sendcvmut, receivecvmut, rendermut; pthread_cond_t sendcv, receivecv; @@ -400,7 +401,8 @@ int main(int argc, char* argv[]) { /* Linked lists to hold messages to be sent and printed */ receivelist = ListCreate(); - sendlist = ListCreate(); + sendlist = ListCreate(); + history = ListCreate(); /* notcurses init */ if (!setlocale(LC_ALL, "")) {