Skip to content

Commit

Permalink
[Hack] free ir->fuse
Browse files Browse the repository at this point in the history
Because ir->fuse is allocated additionally, thus, freeing memory pool
won't fix this issue.

Proper fix for this might actually be allocating from the memory pool
  • Loading branch information
henrybear327 committed Jun 17, 2024
1 parent 6f5c107 commit 3a32c87
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "cache.h"
#include "mpool.h"
#include "riscv_private.h"
#include "utils.h"

static uint32_t cache_size, cache_size_bits;
Expand Down Expand Up @@ -227,6 +228,26 @@ void *cache_put(cache_t *cache, uint32_t key, void *value)

void cache_free(cache_t *cache)
{
#if RV32_HAS(JIT)
for (int i = 0; i < THRESHOLD; i++) {
if (list_empty(cache->lists[i]))
continue;
lfu_entry_t *delete_target =
list_last_entry(cache->lists[i], lfu_entry_t, list);
list_del_init(&delete_target->list);
hlist_del_init(&delete_target->ht_list);
block_t *delete_value = delete_target->value;
mpool_free(cache_mp, delete_target);

uint32_t idx;
rv_insn_t *ir, *next;
for (idx = 0, ir = delete_value->ir_head;
idx < delete_value->n_insn; idx++, ir = next) {
free(ir->fuse);
next = ir->next;
}
}
#endif
for (int i = 0; i < THRESHOLD; i++)
free(cache->lists[i]);
mpool_destroy(cache_mp);
Expand Down

0 comments on commit 3a32c87

Please sign in to comment.