[gamecode] Make modules responsible for freeing resources

It should have been this way all along, and it seems I thought they were
when I did rua_gui.c as it already freed its resource block, which would
have been a double free (oops). Fixes an invalid write when shutting
down progs in qwaq-cmd (relevant change not committed).
This commit is contained in:
Bill Currie 2023-03-03 19:36:28 +09:00
parent 9146860f70
commit 70aa970c32
25 changed files with 31 additions and 2 deletions

View File

@ -105,6 +105,7 @@ bi_il_clear (progs_t *pr, void *_res)
static void
bi_il_destroy (progs_t *pr, void *_res)
{
free (_res);
}
static il_data_t * __attribute__((pure))

View File

@ -407,6 +407,8 @@ pr_debug_destroy (progs_t *pr, void *_res)
Hash_DelTable (res->compunits);
pr->pr_debug_resources = 0;
free (res);
}
static file_t *

View File

@ -79,7 +79,6 @@ PR_Resources_Shutdown (progs_t *pr)
while (res) {
pr_resource_t *t = res->next;
res->destroy (pr, res->data);
free (res->data);
free (res);
res = t;
}

View File

@ -241,6 +241,8 @@ pr_strings_destroy (progs_t *pr, void *_res)
dstring_delete (res->print_str);
Hash_DelTable (res->strref_hash);
pr->pr_string_resources = 0;
free (res);
}
VISIBLE int

View File

@ -116,8 +116,9 @@ bi_gib_builtin_clear (progs_t *progs, void *_res)
static void
bi_gib_builtin_destroy (progs_t *progs, void *_res)
{
//bi_gib_resources_t *res = (bi_gib_resources_t *) _res;
bi_gib_resources_t *res = (bi_gib_resources_t *) _res;
Hash_DelTable (bi_gib_builtins);
free (res);
}
static void

View File

@ -96,6 +96,7 @@ bi_cbuf_clear (progs_t *pr, void *data)
static void
bi_cbuf_destroy (progs_t *pr, void *data)
{
free (data);
}
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}

View File

@ -130,6 +130,7 @@ bi_cmd_destroy (progs_t *pr, void *data)
if (!--bi_cmds_refs) {
Hash_DelTable (bi_cmds);
}
free (data);
}
static void

View File

@ -79,6 +79,7 @@ bi_cvar_clear (progs_t *pr, void *_res)
static void
bi_cvar_destroy (progs_t *pr, void *_res)
{
free (_res);
}
static void

View File

@ -385,6 +385,7 @@ bi_hash_clear (progs_t *pr, void *_res)
static void
bi_hash_destroy (progs_t *pr, void *_res)
{
free (_res);
}
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}

View File

@ -486,6 +486,8 @@ bi_input_destroy (progs_t *pr, void *_res)
input_resources_t *res = _res;
Hash_DelTable (res->cookies);
delete_memsuper (res->cookie_super);
free (res);
}
static uintptr_t

View File

@ -150,6 +150,7 @@ bi_mtwist_clear (progs_t *pr, void *_res)
static void
bi_mtwist_destroy (progs_t *pr, void *_res)
{
free (_res);
}
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}

View File

@ -106,6 +106,7 @@ bi_rua_model_clear (progs_t *pr, void *_res)
static void
bi_rua_model_destroy (progs_t *pr, void *_res)
{
free (_res);
}
static int

View File

@ -97,6 +97,7 @@ bi_msgbuf_clear (progs_t *pr, void *data)
static void
bi_msgbuf_destroy (progs_t *pr, void *_res)
{
free (_res);
}
static int

View File

@ -2332,6 +2332,8 @@ rua_obj_destroy (progs_t *pr, void *_res)
Hash_DelTable (probj->classes);
Hash_DelTable (probj->protocols);
Hash_DelTable (probj->load_methods);
free (probj);
}
void

View File

@ -111,6 +111,7 @@ bi_plist_destroy (progs_t *pr, void *_res)
{
__auto_type res = (plist_resources_t *) _res;
Hash_DelTable (res->plist_tab);
free (res);
}
static inline int

View File

@ -98,6 +98,7 @@ bi_qfile_clear (progs_t *pr, void *_res)
static void
bi_qfile_destroy (progs_t *pr, void *_res)
{
free (_res);
}
static int

View File

@ -657,6 +657,7 @@ bi_scene_clear (progs_t *pr, void *_res)
static void
bi_scene_destroy (progs_t *pr, void *_res)
{
free (_res);
}
void

View File

@ -94,6 +94,7 @@ bi_script_clear (progs_t *pr, void *_res)
static void
bi_script_destroy (progs_t *pr, void *_res)
{
free (_res);
}
static void

View File

@ -806,6 +806,7 @@ res_set_clear (progs_t *pr, void *_res)
static void
res_set_destroy (progs_t *pr, void *_res)
{
free (_res);
}
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}

View File

@ -491,6 +491,8 @@ bi_draw_destroy (progs_t *pr, void *_res)
{
draw_resources_t *res = (draw_resources_t *) _res;
Hash_DelTable (res->pic_hash);
free (res);
}
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}

View File

@ -1864,6 +1864,7 @@ bi_curses_clear (progs_t *pr, void *_res)
static void
bi_curses_destroy (progs_t *pr, void *_res)
{
free (_res);
}
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}}

View File

@ -167,6 +167,7 @@ qwaq_debug_clear (progs_t *pr, void *_res)
static void
qwaq_debug_destroy (progs_t *pr, void *_res)
{
free (_res);
}
static void
@ -181,6 +182,7 @@ qwaq_target_clear (progs_t *pr, void *_res)
static void
qwaq_target_destroy (progs_t *pr, void *_res)
{
// no block to free
}
static int

View File

@ -1020,6 +1020,7 @@ qwaq_ebresources_clear (progs_t *pr, void *_res)
static void
qwaq_ebresources_destroy (progs_t *pr, void *_res)
{
free (_res);
}
#define bi(x,n,np,params...) {#x, bi_##x, n, np, {params}}

View File

@ -200,6 +200,7 @@ qwaq_thread_clear (progs_t *pr, void *_thread)
static void
qwaq_thread_destroy (progs_t *pr, void *_res)
{
// resource block is the thread data: don't own it
}
static progs_t *

View File

@ -892,6 +892,7 @@ bi_input_clear (progs_t *pr, void *_res)
static void
bi_input_destroy (progs_t *pr, void *_res)
{
free (_res);
}
static void