summaryrefslogtreecommitdiff
path: root/ractor.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2021-06-29 14:32:50 -0400
committerPeter Zhu <peter@peterzhu.ca>2021-07-15 11:48:52 -0400
commit4a627dbdfd1165022fa9e716ba845e937b03773d (patch)
tree2dd5c738728ffb2e64816f8a4ffefc82acdc38aa /ractor.c
parent119697f61e2b2b157816a8aa33aada5863959900 (diff)
downloadruby-4a627dbdfd1165022fa9e716ba845e937b03773d.tar.gz
[Bug #18014] Fix memory leak in GC when using Ractors
When a Ractor is removed, the freelist in the Ractor cache is not returned to the GC, leaving the freelist permanently lost. This commit recycles the freelist when the Ractor is destroyed, preventing a memory leak from occurring.
Diffstat (limited to 'ractor.c')
-rw-r--r--ractor.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/ractor.c b/ractor.c
index b5835a8ca6..7996d1c275 100644
--- a/ractor.c
+++ b/ractor.c
@@ -1486,6 +1486,9 @@ vm_remove_ractor(rb_vm_t *vm, rb_ractor_t *cr)
}
vm->ractor.cnt--;
+ /* Clear the cached freelist to prevent a memory leak. */
+ rb_gc_ractor_newobj_cache_clear(&cr->newobj_cache);
+
ractor_status_set(cr, ractor_terminated);
}
RB_VM_UNLOCK();