summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPeter Zhu <[email protected]>2024-07-31 14:18:39 -0400
committerPeter Zhu <[email protected]>2024-08-06 10:19:50 -0400
commitced35800d48e671ed739c8451823c7d3180ef8ac (patch)
treedb9fec2f1f8ea81501a5722d13e80ec6f2febeea /test
parentc0938fd24c927954dbe5d42e70844b6a89516786 (diff)
Fix leak in warning of duplicate keys when Ripper#warn jumps
For example, the following code leaks: class MyRipper < Ripper def initialize(src, &blk) super(src) @blk = blk end def warn(msg, *args) = @blk.call(msg) end $VERBOSE = true def call_parse = MyRipper.new("if true\n end\n") { |msg| return msg }.parse 10.times do 500_000.times do call_parse end puts `ps -o rss= -p #{$$}` end Before: 34832 51952 69760 88048 105344 123040 141152 159152 176656 194272 After: 18400 20256 20272 20272 20272 20304 20368 20368 20368 20400
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11288
Diffstat (limited to 'test')
-rw-r--r--test/ripper/test_parser_events.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index 35264868b9..348e87696a 100644
--- a/test/ripper/test_parser_events.rb
+++ b/test/ripper/test_parser_events.rb
@@ -1765,4 +1765,26 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
end
end;
end
+
+ def test_return_out_of_warn_no_memory_leak
+ assert_no_memory_leak(%w(-rripper), "#{<<~'begin;'}", "#{<<~'end;'}", rss: true)
+ class MyRipper < Ripper
+ def initialize(src, &blk)
+ super(src)
+ @blk = blk
+ end
+
+ def warn(msg, *args) = @blk.call(msg)
+ end
+
+ def call_parse = MyRipper.new("{ a: 1, a: 2 }") { |msg| return msg }.parse
+
+ # Check that call_parse does warn
+ raise "call_parse should warn" unless call_parse
+ begin;
+ 500_000.times do
+ call_parse
+ end
+ end;
+ end
end if ripper_test