summaryrefslogtreecommitdiff
path: root/test/objspace
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2022-02-09 12:14:51 -0800
committerJohn Hawthorn <john@hawthorn.email>2022-02-09 17:32:43 -0800
commit05b1944c53205ffd8c11f1ec2ae6fd48485b55b1 (patch)
treed636fc8f9c26fea58e74439196833282f7e336e3 /test/objspace
parenta271acf82284a8ee665686ab6e95df5622f4b1e2 (diff)
downloadruby-05b1944c53205ffd8c11f1ec2ae6fd48485b55b1.tar.gz
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.
Diffstat (limited to 'test/objspace')
-rw-r--r--test/objspace/test_objspace.rb12
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