[gamecode] Clean up a pile of memory leaks

Usually doesn't matter, but it makes it easier to evaluate valgrind's
output.
This commit is contained in:
Bill Currie 2023-03-03 22:07:27 +09:00
parent 70aa970c32
commit b8bd83f5cd
9 changed files with 53 additions and 3 deletions

View file

@ -1792,6 +1792,14 @@ void *PR_Resources_Find (progs_t *pr, const char *name);
*/ */
#define PR_RESMAP(type) struct { type *_free; type **_map; unsigned _size; } #define PR_RESMAP(type) struct { type *_free; type **_map; unsigned _size; }
#define PR_RESDELMAP(map) \
do { \
for (unsigned i = 0; i < (map)._size; i++) { \
free ((map)._map[i]); \
} \
free ((map)._map); \
} while (0)
/** Allocate a new resource from the resource map. /** Allocate a new resource from the resource map.
\param map The resource map. \param map The resource map.

View file

@ -171,6 +171,9 @@ PR_Builtins_Shutdown (progs_t *pr)
pr->builtin_hash = 0; pr->builtin_hash = 0;
Hash_DelTable (pr->builtin_num_hash); Hash_DelTable (pr->builtin_num_hash);
pr->builtin_num_hash = 0; pr->builtin_num_hash = 0;
free (pr->function_table);
pr->function_table = 0;
} }
VISIBLE builtin_t * VISIBLE builtin_t *

View file

@ -406,6 +406,8 @@ pr_debug_destroy (progs_t *pr, void *_res)
Hash_DelTable (res->debug_syms); Hash_DelTable (res->debug_syms);
Hash_DelTable (res->compunits); Hash_DelTable (res->compunits);
PR_RESDELMAP (res->compmap);
pr->pr_debug_resources = 0; pr->pr_debug_resources = 0;
free (res); free (res);

View file

@ -569,6 +569,15 @@ PR_Shutdown (progs_t *pr)
pr->global_hash = 0; pr->global_hash = 0;
pr->field_hash = 0; pr->field_hash = 0;
pr->type_hash = 0; pr->type_hash = 0;
if (pr->progs) {
pr->free_progs_mem (pr, pr->progs);
}
free (pr->pr_globaldefs);
free (pr->pr_fielddefs);
pr->progs = 0;
pr->pr_globaldefs = 0;
pr->pr_fielddefs = 0;
} }
VISIBLE void VISIBLE void

View file

@ -240,8 +240,15 @@ pr_strings_destroy (progs_t *pr, void *_res)
__auto_type res = (prstr_resources_t *) _res; __auto_type res = (prstr_resources_t *) _res;
dstring_delete (res->print_str); dstring_delete (res->print_str);
Hash_DelTable (res->strref_hash); Hash_DelTable (res->strref_hash);
pr->pr_string_resources = 0; free (res->static_strings);
res->static_strings = 0;
for (unsigned i = 0; i < res->dyn_str_size; i++) {
free (res->string_map[i]);
}
free (res->string_map);
pr->pr_string_resources = 0;
free (res); free (res);
} }

View file

@ -385,7 +385,11 @@ bi_hash_clear (progs_t *pr, void *_res)
static void static void
bi_hash_destroy (progs_t *pr, void *_res) bi_hash_destroy (progs_t *pr, void *_res)
{ {
free (_res); hash_resources_t *res = _res;
PR_RESDELMAP (res->table_map);
free (res);
} }
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}} #define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}

View file

@ -2333,6 +2333,16 @@ rua_obj_destroy (progs_t *pr, void *_res)
Hash_DelTable (probj->protocols); Hash_DelTable (probj->protocols);
Hash_DelTable (probj->load_methods); Hash_DelTable (probj->load_methods);
free (probj->selector_sels);
free (probj->selector_names);
free (probj->selector_argc);
//FIXME free (probj->obj_list_free_list);
//FIXME free (class_tree_free_list);
//FIXME class_tree_free_list = 0;
PR_RESDELMAP (probj->dtables);
free (probj); free (probj);
} }

View file

@ -111,6 +111,9 @@ bi_plist_destroy (progs_t *pr, void *_res)
{ {
__auto_type res = (plist_resources_t *) _res; __auto_type res = (plist_resources_t *) _res;
Hash_DelTable (res->plist_tab); Hash_DelTable (res->plist_tab);
PR_RESDELMAP (res->plist_map);
free (res); free (res);
} }

View file

@ -98,7 +98,11 @@ bi_qfile_clear (progs_t *pr, void *_res)
static void static void
bi_qfile_destroy (progs_t *pr, void *_res) bi_qfile_destroy (progs_t *pr, void *_res)
{ {
free (_res); qfile_resources_t *res = _res;
PR_RESDELMAP (res->handle_map);
free (res);
} }
static int static int