[Ruby 1.9-Bug#4322][Open] valgrind report error for uncaught throw

Bug #4322: valgrind report error for uncaught throw
http://redmine.ruby-lang.org/issues/show/4322

起票者: Tomoyuki C.
ステータス: Open, 優先度: Normal
カテゴリ: core
ruby -v: ruby 1.9.3dev (2011-01-25 trunk 30653) [i686-linux]

以下のようなスクリプトを valgrind を使って実行するとエラーが報告されます。

script

GC.stress = true
throw :tag

message

==1141== Conditional jump or move depends on uninitialised value(s)
==1141== at 0x40276EB: strlen (mc_replace_strmem.c:242)
==1141== by 0x81031DB: BSD_vfprintf (vsnprintf.c:961)
==1141== by 0x81070C4: rb_vsprintf (sprintf.c:1175)
==1141== by 0x81B6628: rb_raise (error.c:1524)
==1141== by 0x8160964: rb_f_throw (vm_eval.c:1441)
==1141== by 0x815D0EC: call_cfunc (vm_insnhelper.c:316)
==1141== by 0x8162468: vm_call_method (vm_insnhelper.c:403)
==1141== by 0x8163C5B: vm_exec_core (insns.def:1010)
==1141== by 0x816947B: vm_exec (vm.c:1150)
==1141== by 0x81697D9: rb_iseq_eval_main (vm.c:1391)
==1141== by 0x805B861: ruby_exec_internal (eval.c:225)
==1141== by 0x805D331: ruby_run_node (eval.c:272)
==1141==
==1141== Conditional jump or move depends on uninitialised value(s)
==1141== at 0x40276F7: strlen (mc_replace_strmem.c:242)
==1141== by 0x81031DB: BSD_vfprintf (vsnprintf.c:961)
==1141== by 0x81070C4: rb_vsprintf (sprintf.c:1175)
==1141== by 0x81B6628: rb_raise (error.c:1524)
==1141== by 0x8160964: rb_f_throw (vm_eval.c:1441)
==1141== by 0x815D0EC: call_cfunc (vm_insnhelper.c:316)
==1141== by 0x8162468: vm_call_method (vm_insnhelper.c:403)
==1141== by 0x8163C5B: vm_exec_core (insns.def:1010)
==1141== by 0x816947B: vm_exec (vm.c:1150)
==1141== by 0x81697D9: rb_iseq_eval_main (vm.c:1391)
==1141== by 0x805B861: ruby_exec_internal (eval.c:225)
==1141== by 0x805D331: ruby_run_node (eval.c:272)
test.rb:2:in throw'==1141== ==1141== Conditional jump or move depends on uninitialised value(s) ==1141== at 0x4027B28: memchr (mc_replace_strmem.c:354) ==1141== by 0x805C2E9: error_print (eval_error.c:144) ==1141== by 0x805CA9A: error_handle (eval_error.c:270) ==1141== by 0x805D05B: ruby_cleanup (eval.c:163) ==1141== by 0x805D339: ruby_run_node (eval.c:265) ==1141== by 0x805AC2F: main (main.c:38) : ==1141== ==1141== Syscall param write(buf) points to uninitialised byte(s) ==1141== at 0x40007F2: (within /lib/ld-2.9.so) ==1141== by 0x4125C95: _IO_file_xsputn (in /lib/tls/i686/cmov/libc-2.9.so) ==1141== by 0x411B6E9: fwrite (in /lib/tls/i686/cmov/libc-2.9.so) ==1141== by 0x8073A4A: rb_write_error2 (io.c:6324) ==1141== by 0x805C314: error_print (eval_error.c:149) ==1141== by 0x805CA9A: error_handle (eval_error.c:270) ==1141== by 0x805D05B: ruby_cleanup (eval.c:163) ==1141== by 0x805D339: ruby_run_node (eval.c:265) ==1141== by 0x805AC2F: main (main.c:38) ==1141== Address 0x4593d37 is 15 bytes inside a block of size 121 alloc'd ==1141== at 0x40270FC: realloc (vg_replace_malloc.c:429) ==1141== by 0x8068D0E: vm_xrealloc (gc.c:727) ==1141== by 0x811F726: rb_str_resize (string.c:1762) ==1141== by 0x81011D1: ruby__sfvwrite (sprintf.c:1148) ==1141== by 0x81021DD: BSD_vfprintf (vsnprintf.c:333) ==1141== by 0x81070C4: rb_vsprintf (sprintf.c:1175) ==1141== by 0x81B6628: rb_raise (error.c:1524) ==1141== by 0x8160964: rb_f_throw (vm_eval.c:1441) ==1141== by 0x815D0EC: call_cfunc (vm_insnhelper.c:316) ==1141== by 0x8162468: vm_call_method (vm_insnhelper.c:403) ==1141== by 0x8163C5B: vm_exec_core (insns.def:1010) ==1141== by 0x816947B: vm_exec (vm.c:1150) uncaught throw :tag (ArgumentError) from test.rb:2:in

チケット #4322 が更新されました。 (by Yui NARUSE)

ちょっと古いものだと確かに再現したのですが、r30653 時点で直ってるように見えます

チケット #4322 が更新されました。 (by Tomoyuki C.)

はい --with-valgrind は付けてます。
すみません、書き忘れてましたが optflags=-O3 を付けてビルドした時に発生します(gcc 4.3.3)。

実はテストケースはソースから逆算して作ったので(#4321 も同様)、以下の RB_GC_GUARD 追加で直ることを確認しています。
すぐ修正するつもりだったのですけど前準備に手間取って一晩寝かせてしまいました。

diff --git a/vm_eval.c b/vm_eval.c
index c67e54c…0dcbafa 100644
— a/vm_eval.c
+++ b/vm_eval.c
@@ -1438,6 +1438,7 @@ rb_throw_obj(VALUE tag, VALUE value)
}
if (!tt) {
VALUE desc = rb_inspect(tag);

  •   RB_GC_GUARD(desc);
      rb_raise(rb_eArgError, "uncaught throw %s", RSTRING_PTR(desc));
    
    }
    rb_trap_restore_mask();

チケット #4322 が更新されました。 (by Yui NARUSE)

あれ、リビジョン同じだな。configureで–with-valgrindは指定してますよね?

チケット #4322 が更新されました。 (by Tomoyuki C.)

ステータス OpenからClosedに変更
進捗 % 0から100に変更

This issue was solved with changeset r30657.
Tomoyuki, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • vm_eval.c (rb_throw_obj): add GC guard to prevent intermediate
    variable from GC. [Bug #4322] [ruby-dev:43108]