diff --git a/ChangeLog b/ChangeLog index 100b072b30..c5dfc6ab59 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Fri Nov 30 07:46:42 2012 Narihiro Nakamura + + * gc.c (rb_objspace_call_finalizer): finalize_deferred may free up + a object which is reachable from a part after this function, + e.g. ruby_vm_destruct(). [ruby-dev:46647] [Bug #7452] + + * test/ruby/test_gc.rb (test_finalizing_main_thread): add a test + for above. + Fri Nov 30 07:43:44 2012 Koichi Sasada * thread.c (rb_thread_interrupted): avoid warning of @@ -462,7 +471,7 @@ Wed Nov 28 16:41:04 2012 Eric Hodel * lib/rdoc/servlet.rb: Add support for serving documentation from a subdirectory. * lib/rdoc/generator/darkfish.rb: ditto - * test/rdoc/test_rdoc_servlet.rb: Test for above + * test/rdoc/test_rdoc_servlet.rb: Tets for above * test/rdoc/test_rdoc_servlet.rb: ditto Wed Nov 28 15:37:17 2012 NARUSE, Yui diff --git a/gc.c b/gc.c index ff8549fad2..b2e7d93256 100644 --- a/gc.c +++ b/gc.c @@ -1504,15 +1504,9 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace) if (ATOMIC_EXCHANGE(finalizing, 1)) return; /* run finalizers */ - do { - finalize_deferred(objspace); - /* mark reachable objects from finalizers */ - /* They might be not referred from any place here */ - mark_tbl(objspace, finalizer_table); - gc_mark_stacked_objects(objspace); - st_foreach(finalizer_table, chain_finalized_object, - (st_data_t)&deferred_final_list); - } while (deferred_final_list); + finalize_deferred(objspace); + assert(deferred_final_list == 0); + /* force to run finalizer */ while (finalizer_table->num_entries) { struct force_finalize_list *list = 0; diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb index 9d68c1a9c0..11d2b4c596 100644 --- a/test/ruby/test_gc.rb +++ b/test/ruby/test_gc.rb @@ -134,4 +134,10 @@ class TestGc < Test::Unit::TestCase ensure GC::Profiler.disable end + + def test_finalizing_main_thread + assert_in_out_err(%w[--disable-gems], <<-EOS, ["\"finalize\""], [], "[ruby-dev:46647]") + ObjectSpace.define_finalizer(Thread.main) { p 'finalize' } + EOS + end end