Skip to content

Commit

Permalink
Free grapheme_lookup tree on full cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Dec 31, 2020
1 parent 97a411e commit fe8a479
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/strings/nfg.c
Expand Up @@ -471,12 +471,25 @@ void MVM_nfg_init(MVMThreadContext *tc) {
cache_crlf(tc);
}

static void nfg_trie_node_destroy(MVMThreadContext *tc, MVMNFGTrieNode *node) {
MVMint32 i = 0;
for(; i < node->num_entries; i++) {
nfg_trie_node_destroy(tc, node->next_codes[i].node);
}
if (node->next_codes)
MVM_fixed_size_free(tc, tc->instance->fsa, node->num_entries * sizeof(MVMNFGTrieNodeEntry), node->next_codes);
MVM_fixed_size_free(tc, tc->instance->fsa, sizeof(MVMNFGTrieNode), node);
}

/* Free all memory allocated to hold synthetic graphemes. These are global
* to a VM instance. */
void MVM_nfg_destroy(MVMThreadContext *tc) {
MVMNFGState *nfg = tc->instance->nfg;
MVMuint32 i;

if (nfg->grapheme_lookup)
nfg_trie_node_destroy(tc, nfg->grapheme_lookup);

/* Free all synthetics. */
if (nfg->synthetics) {
size_t used_synths_in_block = nfg->num_synthetics % MVM_SYNTHETIC_GROW_ELEMS;
Expand Down

0 comments on commit fe8a479

Please sign in to comment.