From 1d11b6fdd6fd79449ae501ddbb98317fdd7134b4 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Mon, 25 May 2015 12:57:49 +0000 Subject: [PATCH] Free alloc'd anims in h_dukeanim. Adds a function hash_loop(). git-svn-id: https://svn.eduke32.com/eduke32@5234 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/build.h | 1 + polymer/eduke32/build/src/engine.c | 10 ++++++++++ polymer/eduke32/build/src/osd.c | 1 + polymer/eduke32/source/game.c | 8 +++++++- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index f299f4f03..9b371b429 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -1407,6 +1407,7 @@ typedef struct } hashtable_t; void hash_init(hashtable_t *t); +void hash_loop(hashtable_t *t, void (*func)(const char *, intptr_t)); void hash_free(hashtable_t *t); intptr_t hash_findcase(const hashtable_t *t, const char *s); intptr_t hash_find(const hashtable_t *t, const char *s); diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index fb915544e..224b690d3 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -18223,6 +18223,16 @@ void hash_init(hashtable_t *t) t->items=(hashitem_t **)Xcalloc(1, t->size * sizeof(hashitem_t)); } +void hash_loop(hashtable_t *t, void (*func)(const char *, intptr_t)) +{ + if (t->items == NULL) + return; + + for (int32_t i=0; i < t->size; i++) + for (hashitem_t *item=t->items[i]; item != NULL; item = item->next) + func(item->string, item->key); +} + void hash_free(hashtable_t *t) { if (t->items == NULL) diff --git a/polymer/eduke32/build/src/osd.c b/polymer/eduke32/build/src/osd.c index cf9081d9f..e1a64fab4 100644 --- a/polymer/eduke32/build/src/osd.c +++ b/polymer/eduke32/build/src/osd.c @@ -674,6 +674,7 @@ void OSD_Cleanup(void) MAYBE_FCLOSE_AND_NULL(osdlog); DO_FREE_AND_NULL(osd->cvars); DO_FREE_AND_NULL(osd->editor.buf); + DO_FREE_AND_NULL(osd->editor.tmp); for (i=0; ihistory.buf[i]); DO_FREE_AND_NULL(osd->text.buf); diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 8e2e92c9e..f67adb4af 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -10827,6 +10827,11 @@ static void G_DisplayLogo(void) clearallviews(0L); } +static void G_FreeHashAnim(const char *UNUSED(string), intptr_t key) +{ + Bfree((void *)key); +} + static void G_Cleanup(void) { int32_t i; @@ -10870,7 +10875,8 @@ static void G_Cleanup(void) hash_free(&h_gamefuncs); #endif - hash_free(&h_dukeanim); // TODO: free the dukeanim_t structs the hash table entries point to + hash_loop(&h_dukeanim, G_FreeHashAnim); + hash_free(&h_dukeanim); } /*