1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Keep vm->orig_progname alive

`vm->orig_progname` can be different from `vm->progname` when user
code assigns to `$0`. While `vm->progname` is kept alive by the
global table, nothing marked `vm->orig_progname`.

[Bug #15887]
This commit is contained in:
Alan Wu 2019-05-30 23:16:27 -04:00 committed by Nobuyoshi Nakada
parent 83f9183a7e
commit ea42423908
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 9 additions and 0 deletions

View file

@ -1400,6 +1400,14 @@ class TestProcess < Test::Unit::TestCase
}
end
def test_argv0_keep_alive
assert_in_out_err([], <<~REPRO, ['-'], [], "[Bug #15887]")
$0 = "diverge"
4.times { GC.start }
puts Process.argv0
REPRO
end
def test_status
with_tmpchdir do
s = run_in_child("exit 1")

1
vm.c
View file

@ -2248,6 +2248,7 @@ rb_vm_mark(void *ptr)
rb_gc_mark(vm->loaded_features);
rb_gc_mark(vm->loaded_features_snapshot);
rb_gc_mark(vm->top_self);
rb_gc_mark(vm->orig_progname);
RUBY_MARK_UNLESS_NULL(vm->coverages);
/* Prevent classes from moving */
rb_mark_tbl(vm->defined_module_hash);