diff --git a/tools/qfcc/include/defspace.h b/tools/qfcc/include/defspace.h index ef6036286..e0414f1c9 100644 --- a/tools/qfcc/include/defspace.h +++ b/tools/qfcc/include/defspace.h @@ -90,6 +90,8 @@ typedef struct defspace_s { */ defspace_t *defspace_new (ds_type_t type); +void defspace_delete (defspace_t *defspace); + /** Allocate space from the defspace's backing memory. If the memory is fragmented, then the first available location at least diff --git a/tools/qfcc/source/defspace.c b/tools/qfcc/source/defspace.c index f2c9f7011..4c3b80ab9 100644 --- a/tools/qfcc/source/defspace.c +++ b/tools/qfcc/source/defspace.c @@ -139,6 +139,28 @@ defspace_new (ds_type_t type) return space; } +void +defspace_delete (defspace_t *space) +{ + locref_t **lr; + + for (lr = &space->free_locs; *lr; lr = &(*lr)->next) { + } + *lr = locrefs_freelist; + locrefs_freelist = space->free_locs; + + if (space->data) { + free (space->data); + } + + while (space->defs) { + def_t *def = space->defs; + space->defs = def->next; + def->space = 0; + free_def (def); + } +} + int defspace_alloc_loc (defspace_t *space, int size) { diff --git a/tools/qfcc/source/qfcc.c b/tools/qfcc/source/qfcc.c index 007c7f795..c606fb414 100644 --- a/tools/qfcc/source/qfcc.c +++ b/tools/qfcc/source/qfcc.c @@ -137,10 +137,15 @@ InitData (void) if (pr.code) { codespace_delete (pr.code); strpool_delete (pr.strings); + defspace_delete (pr.near_data); + defspace_delete (pr.far_data); + defspace_delete (pr.entity_data); + defspace_delete (pr.type_data); } - if (pr.linenos) + if (pr.linenos) { free (pr.linenos); + } memset (&pr, 0, sizeof (pr)); pr.source_line = 1; diff --git a/tools/qfcc/test/test-defspace.c b/tools/qfcc/test/test-defspace.c index 5d14c5013..f0f40a692 100644 --- a/tools/qfcc/test/test-defspace.c +++ b/tools/qfcc/test/test-defspace.c @@ -18,6 +18,12 @@ pr_info_t pr; function_t *current_func; class_type_t *current_class; +void +free_def (def_t *def) +{ + if (0) free (def); +} + __attribute__((const))const char * get_class_name (class_type_t *class_type, int prett) {