diff options
| author | NARUSE, Yui <nurse@users.noreply.github.com> | 2024-03-20 22:40:50 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-20 13:40:50 +0000 |
| commit | c626c201e4129bbea17583ecef73472c6f668c81 (patch) | |
| tree | 04db541d0340a11e8ad842ee63adf30094ca1463 /test/ruby | |
| parent | ce372be903e5f3597f1dc83cb558f165850b3bee (diff) | |
merge revision(s) 01bfd1a2bf013a9ed92a9722ac5228187e05e6a8,1c120efe02d079b0a1dea573cf0fd7978d9cc857,31378dc0969f4466b2122d730b7298dd7004acdf: [Backport #20228] (#10301)
Fix memory leak in OnigRegion when match raises
[Bug #20228]
rb_reg_onig_match can raise a Regexp::TimeoutError, which would cause
the OnigRegion to leak.
Fix memory leak in stk_base when Regexp timeout
[Bug #20228]
If rb_reg_check_timeout raises a Regexp::TimeoutError, then the stk_base
will leak.
Add memory leak test for Regexp timeout
[Bug #20228]
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_regexp.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 0d6ab4682d..4e04ccee69 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -1807,6 +1807,23 @@ class TestRegexp < Test::Unit::TestCase end; end + def test_s_timeout_memory_leak + assert_no_memory_leak([], "#{<<~"begin;"}", "#{<<~"end;"}", "[Bug #20228]", rss: true) + Regexp.timeout = 0.001 + regex = /^(a*)*$/ + str = "a" * 1000000 + "x" + + code = proc do + regex =~ str + rescue + end + + 10.times(&code) + begin; + 1_000.times(&code) + end; + end + def per_instance_redos_test(global_timeout, per_instance_timeout, expected_timeout) assert_separately([], "#{<<-"begin;"}\n#{<<-'end;'}") global_timeout = #{ EnvUtil.apply_timeout_scale(global_timeout).inspect } |
