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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-03-06 10:14:18 +01:00 committed by Dirk Hohndel
parent 805cd550f2
commit 9d2bd425e1

View file

@ -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; \
}