diff options
author | Peter Zhu <peter@peterzhu.ca> | 2023-03-07 09:50:30 -0500 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2023-03-08 08:47:18 -0500 |
commit | e1bd45624c85e8a80991bda20801f50967ac77a1 (patch) | |
tree | 5ddb643dc47a1e63f44dd331fcd0c06caaa4ca84 /test/objspace/test_objspace.rb | |
parent | bead4bce3b4544cb61b3c05c11204a377e20cdfa (diff) |
Fix crash when allocating classes with newobj hook
We need to zero out the whole slot when running the newobj hook for a
newly allocated class because the slot could be filled with garbage,
which would cause a crash if a GC runs inside of the newobj hook.
For example, the following script crashes:
```
require "objspace"
GC.stress = true
ObjectSpace.trace_object_allocations {
100.times do
Class.new
end
}
```
[Bug #19482]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7464
Diffstat (limited to 'test/objspace/test_objspace.rb')
-rw-r--r-- | test/objspace/test_objspace.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index eabfff7876..d9b162ad2b 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -224,6 +224,13 @@ class TestObjSpace < Test::Unit::TestCase 1.0 / 0.0; line4 = __LINE__; c4 = GC.count assert_equal(__FILE__, ObjectSpace.allocation_sourcefile(o4)) assert_equal(line4, ObjectSpace.allocation_sourceline(o4)) + + # [Bug #19482] + EnvUtil.under_gc_stress do + 100.times do + Class.new + end + end } end |