From a6a5a19e289f4110ca5ce177a447fa7788817c73 Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Tue, 11 Jul 2017 19:01:09 +1000 Subject: [PATCH] Fix memory leak in /QUEUE -FLUSH The queue->name must be freed. --- Changelog | 2 ++ source/queue.c | 25 ++++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Changelog b/Changelog index a6d61d6..44b5304 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,7 @@ [Changes 1.2.2] +* Fix memory leak in /QUEUE -FLUSH. (caf) + * Messages sent by /SV and /PASTE should be logged in the send log. (caf) * Change send_text() to combine command, hook and log arguments into one diff --git a/source/queue.c b/source/queue.c index c3d3d66..a6b8901 100644 --- a/source/queue.c +++ b/source/queue.c @@ -267,28 +267,27 @@ static int delete_commands_from_queue (Queue *queue, int which) /* flush a queue, deallocate the memory, and return the next in line */ static Queue *remove_a_queue (Queue *queue) { - Queue *tmp; - tmp = queue->next; + Queue *next = queue->next; + flush_queue(queue); - new_free((char **)&queue); - return tmp; + new_free(&queue->name); + new_free(&queue); + return next; } /* walk through a queue, deallocating the entries */ static void flush_queue (Queue *queue) { - CmdList *tmp, *tmp2; - tmp = queue->first; + CmdList *cmd_list = queue->first; - while (tmp != NULL) + while (cmd_list != NULL) { - tmp2 = tmp; - tmp = tmp2->next; - if (tmp2->what != NULL) - new_free(&tmp2->what); - if (tmp2) - new_free((char **)&tmp2); + CmdList *next = cmd_list->next; + new_free(&cmd_list->what); + new_free(&cmd_list); + cmd_list = next; } + queue->first = NULL; } /*------------------------------------------------------------------------*/