[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 static void
bi_il_destroy (progs_t *pr, void *_res) bi_il_destroy (progs_t *pr, void *_res)
{ {
free (_res);
} }
static il_data_t * __attribute__((pure)) static il_data_t * __attribute__((pure))

View file

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

View file

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

View file

@ -241,6 +241,8 @@ pr_strings_destroy (progs_t *pr, void *_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; pr->pr_string_resources = 0;
free (res);
} }
VISIBLE int VISIBLE int

View file

@ -116,8 +116,9 @@ bi_gib_builtin_clear (progs_t *progs, void *_res)
static void static void
bi_gib_builtin_destroy (progs_t *progs, void *_res) 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); Hash_DelTable (bi_gib_builtins);
free (res);
} }
static void static void

View file

@ -96,6 +96,7 @@ bi_cbuf_clear (progs_t *pr, void *data)
static void static void
bi_cbuf_destroy (progs_t *pr, void *data) bi_cbuf_destroy (progs_t *pr, void *data)
{ {
free (data);
} }
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}} #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) { if (!--bi_cmds_refs) {
Hash_DelTable (bi_cmds); Hash_DelTable (bi_cmds);
} }
free (data);
} }
static void static void

View file

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

View file

@ -385,6 +385,7 @@ 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);
} }
#define bi(x,np,params...) {#x, bi_##x, -1, np, {params}} #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; input_resources_t *res = _res;
Hash_DelTable (res->cookies); Hash_DelTable (res->cookies);
delete_memsuper (res->cookie_super); delete_memsuper (res->cookie_super);
free (res);
} }
static uintptr_t static uintptr_t

View file

@ -150,6 +150,7 @@ bi_mtwist_clear (progs_t *pr, void *_res)
static void static void
bi_mtwist_destroy (progs_t *pr, void *_res) bi_mtwist_destroy (progs_t *pr, void *_res)
{ {
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

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

View file

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

View file

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

View file

@ -111,6 +111,7 @@ 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);
free (res);
} }
static inline int static inline int

View file

@ -98,6 +98,7 @@ 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);
} }
static int static int

View file

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

View file

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

View file

@ -806,6 +806,7 @@ res_set_clear (progs_t *pr, void *_res)
static void static void
res_set_destroy (progs_t *pr, void *_res) res_set_destroy (progs_t *pr, void *_res)
{ {
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

@ -491,6 +491,8 @@ bi_draw_destroy (progs_t *pr, void *_res)
{ {
draw_resources_t *res = (draw_resources_t *) _res; draw_resources_t *res = (draw_resources_t *) _res;
Hash_DelTable (res->pic_hash); Hash_DelTable (res->pic_hash);
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

@ -1864,6 +1864,7 @@ bi_curses_clear (progs_t *pr, void *_res)
static void static void
bi_curses_destroy (progs_t *pr, void *_res) bi_curses_destroy (progs_t *pr, void *_res)
{ {
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

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

View file

@ -1020,6 +1020,7 @@ qwaq_ebresources_clear (progs_t *pr, void *_res)
static void static void
qwaq_ebresources_destroy (progs_t *pr, void *_res) qwaq_ebresources_destroy (progs_t *pr, void *_res)
{ {
free (_res);
} }
#define bi(x,n,np,params...) {#x, bi_##x, n, np, {params}} #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 static void
qwaq_thread_destroy (progs_t *pr, void *_res) qwaq_thread_destroy (progs_t *pr, void *_res)
{ {
// resource block is the thread data: don't own it
} }
static progs_t * static progs_t *

View file

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