From 9d2bd425e12d1d1918e32350c4ea1fc0f259d02f Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 6 Mar 2024 10:14:18 +0100 Subject: [PATCH] core: fix memory leak in tables code The function clear_*_table frees all elements of the table. However, persumably as a performance feature, it kept the memory of the table itselt (i.e. it only reset the number of elements but kept the capacity). That is fine if the table is reused later. However, this function was also used when freeing the table and this would leak the table memory. This commit frees the table memory. An alternative would be to have separate clear_*_table and free_*_table functions. But let's wait with that until we port the table code to C++. Then this will be "automatically" fixed. Signed-off-by: Berthold Stoeger --- core/table.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/table.h b/core/table.h index d12a711eb..1f241e5cb 100644 --- a/core/table.h +++ b/core/table.h @@ -96,6 +96,9 @@ { \ for (int i = 0; i < table->nr; i++) \ free_##item_name(table->array_name[i]); \ + free(table->array_name); \ + table->array_name = NULL; \ + table->allocated = 0; \ table->nr = 0; \ }