From 10756111bf00bc9c9fcbac6f85ab4f24e3787caa Mon Sep 17 00:00:00 2001 From: Holger Vogt Date: Sat, 18 Nov 2023 09:58:30 +0100 Subject: [PATCH] Fix a bug when deleting the memory. With the first call to mem_delete() all the hash table is deleted, a second call to mem_delete() does not have any further effect, so has to be avoided. --- src/spicelib/devices/cpl/cplhash.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/spicelib/devices/cpl/cplhash.c b/src/spicelib/devices/cpl/cplhash.c index 2aaeb5a15..ac2b81586 100644 --- a/src/spicelib/devices/cpl/cplhash.c +++ b/src/spicelib/devices/cpl/cplhash.c @@ -126,6 +126,8 @@ void my_key_free(void * key) void mem_delete(void) { #ifdef DB char buf[128]; + if (!memory_table) + return; printf("CPL GC memory allocated %d times, freed %d times\n", mem_in, mem_out); printf("CPL GC size of hash table to be freed: %d entries.\n", nghash_get_size(memory_table)); #ifdef DB_FULL @@ -142,6 +144,7 @@ void mem_delete(void) { #endif gc_is_on = 0; nghash_free(memory_table, NULL, my_key_free); + memory_table = NULL; #ifdef DB /* printf via sh_printf will need some info from variables that have been deleted already, therefore we use fputs */