ruby-changes:53417
From: shyouhei <ko1@a...>
Date: Thu, 8 Nov 2018 18:46:15 +0900 (JST)
Subject: [ruby-changes:53417] shyouhei:r65633 (trunk): gc.c: avoid integer overflow at process exit
shyouhei 2018-11-08 18:46:09 +0900 (Thu, 08 Nov 2018) New Revision: 65633 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65633 Log: gc.c: avoid integer overflow at process exit This is rather nitpicking but at the moment the process terminates, heap_pages_final_slots overflows. (lldb) bt * thread #1: tid = 0xc0903, 0x00000001002b3bf7 miniruby`finalize_list(objspace=0x0000000101c09240, zombie=4329149840) + 999 at gc.c:2946, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) * frame #0: 0x00000001002b3bf7 miniruby`finalize_list(objspace=0x0000000101c09240, zombie=4329149840) + 999 at gc.c:2946 frame #1: 0x000000010026a69e miniruby`rb_objspace_call_finalizer(objspace=0x0000000101c09240) + 7118 at gc.c:3092 frame #2: 0x0000000100268ac5 miniruby`rb_gc_call_finalizer_at_exit + 149 at gc.c:3015 frame #3: 0x00000001002272bc miniruby`ruby_finalize_1 + 156 at eval.c:146 frame #4: 0x00000001002282b6 miniruby`ruby_cleanup(ex=0) + 4070 at eval.c:238 frame #5: 0x0000000100228785 miniruby`ruby_run_node(n=0x0000000102060ad8) + 85 at eval.c:317 frame #6: 0x0000000100000b9c miniruby`main(argc=2, argv=0x00007fff5fbfdc38) + 124 at main.c:42 frame #7: 0x00007fff9966a5ad libdyld.dylib`start + 1 frame #8: 0x00007fff9966a5ad libdyld.dylib`start + 1 (lldb) p objspace->heap_pages (rb_objspace::(anonymous struct)) $0 = { sorted = 0x0000000101c070b0 allocated_pages = 24 allocatable_pages = 0 sorted_length = 24 range = { [0] = 0x0000000102020028 [1] = 0x00000001020dbfd0 } freeable_pages = 0 final_slots = 0 deferred_final = 4329149840 } (lldb) Modified files: trunk/gc.c Index: gc.c =================================================================== --- gc.c (revision 65632) +++ gc.c (revision 65633) @@ -2943,7 +2943,7 @@ finalize_list(rb_objspace_t *objspace, V https://github.com/ruby/ruby/blob/trunk/gc.c#L2943 run_final(objspace, zombie); RZOMBIE(zombie)->basic.flags = 0; - heap_pages_final_slots--; + if (LIKELY(heap_pages_final_slots)) heap_pages_final_slots--; page->final_slots--; page->free_slots++; heap_page_add_freeobj(objspace, GET_HEAP_PAGE(zombie), zombie); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/