Issue #11846 has been updated by Tomoyuki Chikanaga.

Status changed from Open to Closed
Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: DONTNEED

wanabe san, Thank you for your investigation!
So this issue is already fixed on both 2.3/trunk and not exist on 2.2 and before.
I'll close this ticket and fill Backport field.

----------------------------------------
Bug #11846: Block passed by &block is GC-ed
https://bugs.ruby-lang.org/issues/11846#change-60277

* Author: Kouhei Sutou
* Status: Closed
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0preview2 (2015-12-11 trunk 53028) [x86_64-linux]
* Backport: 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: DONTNEED
----------------------------------------
The following script is crashed with ruby 2.3.0preview2:

```ruby
GC.start

def a
  lambda do
    yield
  end
end

def b(&block)
  a(&block)
end

def proc_sources
  sources = []
  ObjectSpace.each_object(Proc) do |proc|
    sources << proc.source_location.join(":")
  end
  sources
end

c = b {p 1}

old_proc_sources = proc_sources
GC.start
new_proc_sources = proc_sources
p(old_proc_sources - new_proc_sources)

c.call
```

Because passed block (`{p 1}`) at the following line is GC-ed:

```ruby
c = b {p 1}
```

```text
% /tmp/local/bin/ruby -v /tmp/a.rb
ruby 2.3.0preview2 (2015-12-11 trunk 53028) [x86_64-linux]
["/tmp/a.rb:21"]
/tmp/a.rb:21: [BUG] Segmentation fault at 0x00000000000020
ruby 2.3.0preview2 (2015-12-11 trunk 53028) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0004 p:0009 s:0013 e:000010 LAMBDA /tmp/a.rb:21
c:0003 p:0006 s:0009 e:000008 LAMBDA /tmp/a.rb:5 [FINISH]
c:0002 p:0108 s:0007 E:000098 EVAL   /tmp/a.rb:28 [FINISH]
c:0001 p:0000 s:0002 E:002490 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
/tmp/a.rb:28:in `<main>'
/tmp/a.rb:5:in `block in a'
/tmp/a.rb:21:in `block in <main>'

-- Machine register context ------------------------------------------------
 RIP: 0x000055c7ce5b0390 RBP: 0x00007ffc593be9b0 RSP: 0x00007ffc593be998
 RAX: 0x0000000000000020 RBX: 0x0000000000000001 RCX: 0x0000000000003b21
 RDX: 0x00007ffc593be9d0 RDI: 0x0000000000000020 RSI: 0x0000000000003b21
  R8: 0x000055c7cf429c31  R9: 0x0000000000000000 R10: 0x00000000000000a1
 R11: 0x0000000000000002 R12: 0x000055c7ce4bf730 R13: 0x00007ffc593c1310
 R14: 0x000055c7cf6d97b8 R15: 0x00007f82e0ed4f10 EFL: 0x0000000000010212

-- C level backtrace information -------------------------------------------
/tmp/local/bin/ruby(rb_print_backtrace+0x19) [0x55c7ce6198d7] vm_dump.c:688
/tmp/local/bin/ruby(rb_vm_bugreport+0xa9) [0x55c7ce619d4a] vm_dump.c:997
/tmp/local/bin/ruby(rb_bug_context+0x114) [0x55c7ce6758fe] error.c:423
/tmp/local/bin/ruby(sigsegv+0x5e) [0x55c7ce580b9c] signal.c:890
/lib/x86_64-linux-gnu/libpthread.so.0 [0x7f82e0ae2670]
/tmp/local/bin/ruby(rb_id_table_lookup+0x18) [0x55c7ce5b0390] id_table.c:1516
/tmp/local/bin/ruby(lookup_method_table+0x33) [0x55c7ce60907d] vm_method.c:189
/tmp/local/bin/ruby(search_method+0x31) [0x55c7ce60a247] vm_method.c:679
/tmp/local/bin/ruby(method_entry_get_without_cache+0x2b) [0x55c7ce60a2d4] vm_method.c:704
/tmp/local/bin/ruby(method_entry_get+0xb8) [0x55c7ce60a46f] vm_method.c:764
/tmp/local/bin/ruby(rb_callable_method_entry+0x27) [0x55c7ce60a592] vm_method.c:809
/tmp/local/bin/ruby(vm_search_method+0x78) [0x55c7ce5faf91] vm_insnhelper.c:1132
/tmp/local/bin/ruby(vm_exec_core+0x253c) [0x55c7ce603918] insns.def:994
/tmp/local/bin/ruby(vm_exec+0xe4) [0x55c7ce614e25] vm.c:1637
/tmp/local/bin/ruby(invoke_block+0xd2) [0x55c7ce612dda] vm.c:911
/tmp/local/bin/ruby(invoke_block_from_c_0+0x208) [0x55c7ce613196] vm.c:961
/tmp/local/bin/ruby(invoke_block_from_c_unsplattable+0x49) [0x55c7ce613282] vm.c:986
/tmp/local/bin/ruby(vm_invoke_proc+0x147) [0x55c7ce613527] vm.c:1034
/tmp/local/bin/ruby(rb_vm_invoke_proc+0x7e) [0x55c7ce613658] vm.c:1062
/tmp/local/bin/ruby(vm_call_opt_call+0x15c) [0x55c7ce5ff656] vm_insnhelper.c:1935
/tmp/local/bin/ruby(vm_call_method_each_type+0x375) [0x55c7ce5fff5f] vm_insnhelper.c:2128
/tmp/local/bin/ruby(vm_call_method+0x77) [0x55c7ce600333] vm_insnhelper.c:2215
/tmp/local/bin/ruby(vm_call_general+0x3b) [0x55c7ce600509] vm_insnhelper.c:2258
/tmp/local/bin/ruby(vm_exec_core+0x256e) [0x55c7ce60394a] insns.def:995
/tmp/local/bin/ruby(vm_exec+0xe4) [0x55c7ce614e25] vm.c:1637
/tmp/local/bin/ruby(rb_iseq_eval_main+0x36) [0x55c7ce615a70] vm.c:1880
/tmp/local/bin/ruby(ruby_exec_internal+0x135) [0x55c7ce4c1d4b] eval.c:244
/tmp/local/bin/ruby(ruby_exec_node+0x24) [0x55c7ce4c1e74] eval.c:309
/tmp/local/bin/ruby(ruby_run_node+0x3e) [0x55c7ce4c1e47] eval.c:301
/tmp/local/bin/ruby(main+0x5d) [0x55c7ce4bf8bd] main.c:36

-- Other runtime information -----------------------------------------------

* Loaded script: /tmp/a.rb

* Loaded features:

    0 enumerator.so
    1 thread.rb
    2 rational.so
    3 complex.so
    4 /tmp/local/lib/ruby/2.3.0/x86_64-linux/enc/encdb.so
    5 /tmp/local/lib/ruby/2.3.0/x86_64-linux/enc/trans/transdb.so
    6 /tmp/local/lib/ruby/2.3.0/unicode_normalize.rb
    7 /tmp/local/lib/ruby/2.3.0/x86_64-linux/rbconfig.rb
    8 /tmp/local/lib/ruby/2.3.0/rubygems/compatibility.rb
    9 /tmp/local/lib/ruby/2.3.0/rubygems/defaults.rb
   10 /tmp/local/lib/ruby/2.3.0/rubygems/deprecate.rb
   11 /tmp/local/lib/ruby/2.3.0/rubygems/errors.rb
   12 /tmp/local/lib/ruby/2.3.0/rubygems/version.rb
   13 /tmp/local/lib/ruby/2.3.0/rubygems/requirement.rb
   14 /tmp/local/lib/ruby/2.3.0/rubygems/platform.rb
   15 /tmp/local/lib/ruby/2.3.0/rubygems/basic_specification.rb
   16 /tmp/local/lib/ruby/2.3.0/rubygems/stub_specification.rb
   17 /tmp/local/lib/ruby/2.3.0/rubygems/util/list.rb
   18 /tmp/local/lib/ruby/2.3.0/x86_64-linux/stringio.so
   19 /tmp/local/lib/ruby/2.3.0/rubygems/specification.rb
   20 /tmp/local/lib/ruby/2.3.0/rubygems/exceptions.rb
   21 /tmp/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb
   22 /tmp/local/lib/ruby/2.3.0/monitor.rb
   23 /tmp/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb
   24 /tmp/local/lib/ruby/2.3.0/rubygems.rb
   25 /tmp/local/lib/ruby/2.3.0/rubygems/path_support.rb
   26 /tmp/local/lib/ruby/2.3.0/rubygems/dependency.rb
   27 /tmp/local/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0.rc1/lib/did_you_mean/version.rb
   28 /tmp/local/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0.rc1/lib/did_you_mean/core_ext/name_error.rb
   29 /tmp/local/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0.rc1/lib/did_you_mean/levenshtein.rb
   30 /tmp/local/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0.rc1/lib/did_you_mean/jaro_winkler.rb
   31 /tmp/local/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0.rc1/lib/did_you_mean/spell_checkable.rb
   32 /tmp/local/lib/ruby/2.3.0/delegate.rb
   33 /tmp/local/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0.rc1/lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb
   34 /tmp/local/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0.rc1/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb
   35 /tmp/local/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0.rc1/lib/did_you_mean/spell_checkers/name_error_checkers.rb
   36 /tmp/local/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0.rc1/lib/did_you_mean/spell_checkers/method_name_checker.rb
   37 /tmp/local/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0.rc1/lib/did_you_mean/spell_checkers/null_checker.rb
   38 /tmp/local/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0.rc1/lib/did_you_mean/formatter.rb
   39 /tmp/local/lib/ruby/gems/2.3.0/gems/did_you_mean-1.0.0.rc1/lib/did_you_mean.rb

* Process memory map:

55c7ce49d000-55c7ce76c000 r-xp 00000000 08:01 7870884                    /tmp/local/bin/ruby
55c7ce96c000-55c7ce972000 rw-p 002cf000 08:01 7870884                    /tmp/local/bin/ruby
55c7ce972000-55c7ce984000 rw-p 00000000 00:00 0 
55c7cf2b8000-55c7cf6ea000 rw-p 00000000 00:00 0                          [heap]
7f82deb7a000-7f82ded1c000 r--s 00000000 08:01 3670782                    /lib/x86_64-linux-gnu/libc-2.21.so
7f82ded1c000-7f82df2d1000 r--s 00000000 08:01 7870884                    /tmp/local/bin/ruby
7f82df2d1000-7f82df2e7000 r-xp 00000000 08:01 3670262                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f82df2e7000-7f82df4e6000 ---p 00016000 08:01 3670262                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f82df4e6000-7f82df4e7000 rw-p 00015000 08:01 3670262                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f82df4e7000-7f82df4ef000 r-xp 00000000 08:01 8396063                    /tmp/local/lib/ruby/2.3.0/x86_64-linux/stringio.so
7f82df4ef000-7f82df6ee000 ---p 00008000 08:01 8396063                    /tmp/local/lib/ruby/2.3.0/x86_64-linux/stringio.so
7f82df6ee000-7f82df6ef000 rw-p 00007000 08:01 8396063                    /tmp/local/lib/ruby/2.3.0/x86_64-linux/stringio.so
7f82df6ef000-7f82df6f1000 r-xp 00000000 08:01 9577347                    /tmp/local/lib/ruby/2.3.0/x86_64-linux/enc/trans/transdb.so
7f82df6f1000-7f82df8f1000 ---p 00002000 08:01 9577347                    /tmp/local/lib/ruby/2.3.0/x86_64-linux/enc/trans/transdb.so
7f82df8f1000-7f82df8f2000 rw-p 00002000 08:01 9577347                    /tmp/local/lib/ruby/2.3.0/x86_64-linux/enc/trans/transdb.so
7f82df8f2000-7f82df8f4000 r-xp 00000000 08:01 9577366                    /tmp/local/lib/ruby/2.3.0/x86_64-linux/enc/encdb.so
7f82df8f4000-7f82dfaf3000 ---p 00002000 08:01 9577366                    /tmp/local/lib/ruby/2.3.0/x86_64-linux/enc/encdb.so
7f82dfaf3000-7f82dfaf4000 rw-p 00001000 08:01 9577366                    /tmp/local/lib/ruby/2.3.0/x86_64-linux/enc/encdb.so
7f82dfaf4000-7f82dfd6b000 r--p 00000000 08:01 13107345                   /usr/lib/locale/locale-archive
7f82dfd6b000-7f82dff05000 r-xp 00000000 08:01 3670782                    /lib/x86_64-linux-gnu/libc-2.21.so
7f82dff05000-7f82e0105000 ---p 0019a000 08:01 3670782                    /lib/x86_64-linux-gnu/libc-2.21.so
7f82e0105000-7f82e0109000 r--p 0019a000 08:01 3670782                    /lib/x86_64-linux-gnu/libc-2.21.so
7f82e0109000-7f82e010b000 rw-p 0019e000 08:01 3670782                    /lib/x86_64-linux-gnu/libc-2.21.so
7f82e010b000-7f82e010f000 rw-p 00000000 00:00 0 
7f82e010f000-7f82e0212000 r-xp 00000000 08:01 3672049                    /lib/x86_64-linux-gnu/libm-2.21.so
7f82e0212000-7f82e0412000 ---p 00103000 08:01 3672049                    /lib/x86_64-linux-gnu/libm-2.21.so
7f82e0412000-7f82e0413000 r--p 00103000 08:01 3672049                    /lib/x86_64-linux-gnu/libm-2.21.so
7f82e0413000-7f82e0414000 rw-p 00104000 08:01 3672049                    /lib/x86_64-linux-gnu/libm-2.21.so
7f82e0414000-7f82e041c000 r-xp 00000000 08:01 3670802                    /lib/x86_64-linux-gnu/libcrypt-2.21.so
7f82e041c000-7f82e061b000 ---p 00008000 08:01 3670802                    /lib/x86_64-linux-gnu/libcrypt-2.21.so
7f82e061b000-7f82e061c000 r--p 00007000 08:01 3670802                    /lib/x86_64-linux-gnu/libcrypt-2.21.so
7f82e061c000-7f82e061d000 rw-p 00008000 08:01 3670802                    /lib/x86_64-linux-gnu/libcrypt-2.21.so
7f82e061d000-7f82e064b000 rw-p 00000000 00:00 0 
7f82e064b000-7f82e064d000 r-xp 00000000 08:01 3670804                    /lib/x86_64-linux-gnu/libdl-2.21.so
7f82e064d000-7f82e084d000 ---p 00002000 08:01 3670804                    /lib/x86_64-linux-gnu/libdl-2.21.so
7f82e084d000-7f82e084e000 r--p 00002000 08:01 3670804                    /lib/x86_64-linux-gnu/libdl-2.21.so
7f82e084e000-7f82e084f000 rw-p 00003000 08:01 3670804                    /lib/x86_64-linux-gnu/libdl-2.21.so
7f82e084f000-7f82e08d1000 r-xp 00000000 08:01 13107704                   /usr/lib/x86_64-linux-gnu/libgmp.so.10.3.0
7f82e08d1000-7f82e0ad0000 ---p 00082000 08:01 13107704                   /usr/lib/x86_64-linux-gnu/libgmp.so.10.3.0
7f82e0ad0000-7f82e0ad1000 r--p 00081000 08:01 13107704                   /usr/lib/x86_64-linux-gnu/libgmp.so.10.3.0
7f82e0ad1000-7f82e0ad2000 rw-p 00082000 08:01 13107704                   /usr/lib/x86_64-linux-gnu/libgmp.so.10.3.0
7f82e0ad2000-7f82e0aea000 r-xp 00000000 08:01 3670245                    /lib/x86_64-linux-gnu/libpthread-2.21.so
7f82e0aea000-7f82e0ce9000 ---p 00018000 08:01 3670245                    /lib/x86_64-linux-gnu/libpthread-2.21.so
7f82e0ce9000-7f82e0cea000 r--p 00017000 08:01 3670245                    /lib/x86_64-linux-gnu/libpthread-2.21.so
7f82e0cea000-7f82e0ceb000 rw-p 00018000 08:01 3670245                    /lib/x86_64-linux-gnu/libpthread-2.21.so
7f82e0ceb000-7f82e0cef000 rw-p 00000000 00:00 0 
7f82e0cef000-7f82e0d11000 r-xp 00000000 08:01 3670248                    /lib/x86_64-linux-gnu/ld-2.21.so
7f82e0dd5000-7f82e0edb000 rw-p 00000000 00:00 0 
7f82e0ee0000-7f82e0ee1000 rw-p 00000000 00:00 0 
7f82e0ee1000-7f82e0f02000 r--s 00000000 08:01 3670245                    /lib/x86_64-linux-gnu/libpthread-2.21.so
7f82e0f02000-7f82e0f09000 r--s 00000000 08:01 13147175                   /usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache
7f82e0f09000-7f82e0f0a000 rw-p 00000000 00:00 0 
7f82e0f0a000-7f82e0f0b000 ---p 00000000 00:00 0 
7f82e0f0b000-7f82e0f10000 rw-p 00000000 00:00 0                          [stack:23579]
7f82e0f10000-7f82e0f11000 r--p 00021000 08:01 3670248                    /lib/x86_64-linux-gnu/ld-2.21.so
7f82e0f11000-7f82e0f12000 rw-p 00022000 08:01 3670248                    /lib/x86_64-linux-gnu/ld-2.21.so
7f82e0f12000-7f82e0f13000 rw-p 00000000 00:00 0 
7ffc58bc4000-7ffc593c3000 rw-p 00000000 00:00 0 
7ffc593ca000-7ffc593cc000 r--p 00000000 00:00 0                          [vvar]
7ffc593cc000-7ffc593ce000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]


[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>