Skip to content

Commit d7d1a6d

Browse files
committed
[Hack] free ir->fuse
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
1 parent cc9f24b commit d7d1a6d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/cache.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "cache.h"
1414
#include "mpool.h"
15+
#include "riscv_private.h"
1516
#include "utils.h"
1617

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

228229
void cache_free(cache_t *cache)
229230
{
231+
#if RV32_HAS(JIT)
232+
for (int i = 0; i < THRESHOLD; i++) {
233+
if (list_empty(cache->lists[i]))
234+
continue;
235+
lfu_entry_t *delete_target =
236+
list_last_entry(cache->lists[i], lfu_entry_t, list);
237+
list_del_init(&delete_target->list);
238+
hlist_del_init(&delete_target->ht_list);
239+
block_t *delete_value = delete_target->value;
240+
mpool_free(cache_mp, delete_target);
241+
242+
uint32_t idx;
243+
rv_insn_t *ir, *next;
244+
for (idx = 0, ir = delete_value->ir_head;
245+
idx < delete_value->n_insn; idx++, ir = next) {
246+
free(ir->fuse);
247+
next = ir->next;
248+
}
249+
}
250+
#endif
230251
for (int i = 0; i < THRESHOLD; i++)
231252
free(cache->lists[i]);
232253
mpool_destroy(cache_mp);

0 commit comments

Comments
 (0)