diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-02-07 19:37:55 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-02-07 19:37:55 -0500 |
commit | d81bd17093ecda178bae3281cfe79180fc21a416 (patch) | |
tree | b754e1779200e0dd7f64be4c71267bd090ab9128 | |
parent | f94bf833f031611b49fa9674af44dba1f55e7c24 (diff) |
fixed leaks
-rw-r--r-- | cgen.c | 6 | ||||
-rw-r--r-- | data_structures.c | 10 | ||||
-rw-r--r-- | toc.c | 1 | ||||
-rw-r--r-- | types.c | 4 |
4 files changed, 15 insertions, 6 deletions
@@ -13,7 +13,7 @@ static void cgen_create(CGenerator *g, FILE *out, Identifiers *ids, Evaluator *e g->globals = ids; g->allocr = allocr; g->nms_prefix = NULL; - *(char *)arr_add(&g->nms_prefix) = '\0'; + *(char *)arr_adda(&g->nms_prefix, g->allocr) = '\0'; } static bool cgen_stmt(CGenerator *g, Statement *s); @@ -287,7 +287,7 @@ static void cgen_nms_enter(CGenerator *g, Namespace *n) { char *s = cgen_nms_prefix(g, n); size_t chars_so_far = arr_len(g->nms_prefix) - 1; /* -1 for '\0' byte */ size_t new_chars = strlen(s) + 1; /* + 1 for '\0' byte */ - arr_set_len(&g->nms_prefix, chars_so_far + new_chars); + arr_set_lena(&g->nms_prefix, chars_so_far + new_chars, g->allocr); for (size_t i = 0; i < new_chars; ++i) { g->nms_prefix[i+chars_so_far] = s[i]; } @@ -296,7 +296,7 @@ static void cgen_nms_enter(CGenerator *g, Namespace *n) { static void cgen_nms_exit(CGenerator *g, Namespace *n, Namespace *prev) { char *s = cgen_nms_prefix(g, n); - arr_set_len(&g->nms_prefix, arr_len(g->nms_prefix) - strlen(s)); + arr_set_lena(&g->nms_prefix, arr_len(g->nms_prefix) - strlen(s), g->allocr); g->nms = prev; free(s); } diff --git a/data_structures.c b/data_structures.c index 8efa124..1aac916 100644 --- a/data_structures.c +++ b/data_structures.c @@ -89,6 +89,10 @@ static void arr_cleara_(void **arr, size_t size, Allocator *allocr) { } static void arr_set_len_(void **arr, size_t n, size_t item_sz) { + if (n == 0) { + arr_clear_(arr); + return; + } if (n > arr_len(*arr)) { arr_resv_(arr, n, item_sz); } @@ -96,6 +100,10 @@ static void arr_set_len_(void **arr, size_t n, size_t item_sz) { /* OPTIM: shrink */ } static void arr_set_lena_(void **arr, size_t n, size_t item_sz, Allocator *a) { + if (n == 0) { + arr_cleara_(arr, item_sz, a); + return; + } arr_resva_(arr, n, item_sz, a); arr_hdr(*arr)->len = n; } @@ -272,7 +280,7 @@ static void str_hash_table_grow(StrHashTable *t) { if (slots_cap <= 2 * t->nentries) { StrHashTableSlot **new_slots = NULL; size_t new_slots_cap = slots_cap * 2 + 10; - arr_set_len(&new_slots, new_slots_cap); + arr_set_lena(&new_slots, new_slots_cap, t->allocr); arr_zero(new_slots); arr_foreach(t->slots, StrHashTableSlotPtr, slotp) { StrHashTableSlot *slot = *slotp; @@ -107,6 +107,7 @@ static char *read_file_contents(Allocator *a, const char *filename, Location whe } } ++contents; + fclose(in); return contents; } @@ -20,12 +20,12 @@ static inline void *typer_arr_add_(Typer *tr, void **arr, size_t sz) { } static inline void typer_block_enter(Typer *tr, Block *b) { - *(Block **)arr_add(&tr->blocks) = b; + *(Block **)arr_adda(&tr->blocks, tr->allocr) = b; tr->block = b; } static inline void typer_block_exit(Typer *tr) { - arr_remove_last(&tr->blocks); + arr_remove_lasta(&tr->blocks, tr->allocr); tr->block = *(Block **)arr_last(tr->blocks); } |