Project

General

Profile

Actions

Bug #20228

closed

Memory leak in Regexp timeout

Added by peterzhu2118 (Peter Zhu) 4 months ago. Updated about 2 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:116514]

Description

GitHub PR: https://github.com/ruby/ruby/pull/9765

If a Regexp::TimeoutError is raised, the stk_base and OnigRegion will leak.

For example:

Regexp.timeout = 0.001
regex = /^(a*)*$/
str = "a" * 1000000 + "x"

10.times do
  100.times do
    begin
      regex =~ str
    rescue
    end
  end

  puts `ps -o rss= -p #{$$}`
end

Before:

328800
632416
934368
1230448
1531088
1831248
2125072
2414384
2703440
2995664

After:

39280
47888
49024
56240
56496
56512
56592
56592
56720
56720
Actions

Also available in: Atom PDF

Like0
Like0Like0Like1Like0Like0