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.

This commit is contained in:
2026-09-26 13:22:20 -06:00
parent d9527bacc7
commit cc793e134a
+3 -1
View File
@@ -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;
@@ -401,6 +402,7 @@ int main(int argc, char* argv[]) {
/* Linked lists to hold messages to be sent and printed */
receivelist = ListCreate();
sendlist = ListCreate();
history = ListCreate();
/* notcurses init */
if (!setlocale(LC_ALL, "")) {