Skip to content

Commit

Permalink
Fix leaking native callback cache on thread exit
Browse files Browse the repository at this point in the history
  • Loading branch information
niner committed Mar 27, 2020
1 parent 2829898 commit 7748409
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/core/threadcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ void MVM_tc_destroy(MVMThreadContext *tc) {
MVM_free(tc->temp_bigints[i]);
}

MVM_HASH_DESTROY(tc, hash_handle, MVMNativeCallbackCacheHead, tc->native_callback_cache);

/* Free the thread context itself. */
memset(tc, 0xfe, sizeof(MVMThreadContext));
MVM_free(tc);
Expand Down
4 changes: 2 additions & 2 deletions src/jit/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ MVMJitCode* MVM_jit_code_copy(MVMThreadContext *tc, MVMJitCode * const code) {
}

void MVM_jit_code_destroy(MVMThreadContext *tc, MVMJitCode *code) {
/* fetch_and_sub1 returns previous value, therefore subtract 1 for the test */
if (AO_fetch_and_sub1(&code->ref_cnt) - 1 > 0)
/* fetch_and_sub1 returns previous value, so check if there's only 1 reference */
if (AO_fetch_and_sub1(&code->ref_cnt) > 1)
return;
MVM_platform_free_pages(code->func_ptr, code->size);
MVM_free(code->labels);
Expand Down

0 comments on commit 7748409

Please sign in to comment.