From 46f7fac878540fd555b502a2c5a5b5e2a6c7413f Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Wed, 3 Jan 2024 09:53:55 -0500 Subject: [PATCH] Free rb_native_thread of main thread The rb_native_thread gets reported as a memory leak by the macOS leaks tool: $ RUBY_FREE_AT_EXIT=1 leaks -q --atExit -- ./miniruby -e "" STACK OF 1 INSTANCE OF 'ROOT LEAK: ': 6 dyld 0x1818a90e0 start + 2360 5 miniruby 0x104730128 main + 88 main.c:58 4 miniruby 0x1047d7710 ruby_init + 16 eval.c:102 3 miniruby 0x1047d757c ruby_setup + 112 eval.c:83 2 miniruby 0x104977278 Init_BareVM + 524 vm.c:4193 1 miniruby 0x1047f2478 ruby_xcalloc_body + 176 gc.c:12878 0 libsystem_malloc.dylib 0x181a67b78 _malloc_zone_calloc_instrumented_or_legacy + 100 ==== 1 (176 bytes) ROOT LEAK: [176] --- vm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vm.c b/vm.c index 96f4189b14..257c517b43 100644 --- a/vm.c +++ b/vm.c @@ -3029,6 +3029,11 @@ ruby_vm_destruct(rb_vm_t *vm) st_free_table(vm->defined_module_hash); rb_id_table_free(vm->constant_cache); + + if (th) { + xfree(th->nt); + th->nt = NULL; + } } else { if (th) {