diff options
author | John Hawthorn <[email protected]> | 2022-02-09 12:14:51 -0800 |
---|---|---|
committer | John Hawthorn <[email protected]> | 2022-02-09 17:32:43 -0800 |
commit | 05b1944c53205ffd8c11f1ec2ae6fd48485b55b1 (patch) | |
tree | d636fc8f9c26fea58e74439196833282f7e336e3 /test/objspace/test_objspace.rb | |
parent | a271acf82284a8ee665686ab6e95df5622f4b1e2 (diff) |
objspace: Hide identhash containing internal objs
Inside ObjectSpace.reachable_objects_from we keep an internal identhash
in order to de-duplicate reachable objects when wrapping them as
InternalObject. Previously this hash was not hidden, making it possible
to leak references to those internal objects to Ruby if using
ObjectSpace.each_object.
This commit solves this by hiding the hash. To simplify collection of
values, we instead now just use the hash as a set of visited objects,
and collect an Array (not hidden) of values to be returned.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5542
Diffstat (limited to 'test/objspace/test_objspace.rb')
-rw-r--r-- | test/objspace/test_objspace.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/objspace/test_objspace.rb b/test/objspace/test_objspace.rb index 34d9dd76ec..781fb5b3c2 100644 --- a/test/objspace/test_objspace.rb +++ b/test/objspace/test_objspace.rb @@ -140,6 +140,18 @@ class TestObjSpace < Test::Unit::TestCase end; end + def test_reachable_objects_during_iteration + opts = %w[--disable-gem --disable=frozen-string-literal -robjspace] + assert_separately opts, "#{<<-"begin;"}\n#{<<-'end;'}" + begin; + ObjectSpace.each_object{|o| + o.inspect + ObjectSpace.reachable_objects_from(Class) + } + end; + end + + def test_reachable_objects_from_root root_objects = ObjectSpace.reachable_objects_from_root |