diff options
| author | nagachika <nagachika@ruby-lang.org> | 2023-07-16 12:58:21 +0900 |
|---|---|---|
| committer | nagachika <nagachika@ruby-lang.org> | 2023-07-16 12:58:21 +0900 |
| commit | 141402d11c09fa641eebd8f4841f81e7bbf3518c (patch) | |
| tree | 40c353f0d0b9f6e8fe03694d2c8de470d62f82d2 /test | |
| parent | 44a8e5e63a5f0a2bd13628ee6c1cb4634f828d16 (diff) | |
merge revision(s) e1bd45624c85e8a80991bda20801f50967ac77a1: [Backport #19482]
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]
---
gc.c | 8 +++++++-
test/objspace/test_objspace.rb | 7 +++++++
2 files changed, 14 insertions(+), 1 deletion(-)
Diffstat (limited to 'test')
| -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 f0f294c31a..7556fca530 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -216,6 +216,13 @@ class TestObjSpace < Test::Unit::TestCase assert_equal(c3, ObjectSpace.allocation_generation(o3)) assert_equal(self.class.name, ObjectSpace.allocation_class_path(o3)) assert_equal(__method__, ObjectSpace.allocation_method_id(o3)) + + # [Bug #19482] + EnvUtil.under_gc_stress do + 100.times do + Class.new + end + end } end |
