Project

General

Profile

Actions

Bug #20650

closed

Memory leak in Regexp capture group when timeout

Added by peterzhu2118 (Peter Zhu) 1 day ago. Updated about 9 hours ago.

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

Description

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

The capture group allocates memory that is leaked when it times out.

For example:

re = Regexp.new("^#{"(a*)" * 10_000}x$", timeout: 0.000001)
str = "a" * 1000000 + "x"

10.times do
  100.times do
    re =~ str
  rescue Regexp::TimeoutError
  end

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

Before:

34688
56416
78288
100368
120784
140704
161904
183568
204320
224800

After:

16288
16288
16880
16896
16912
16928
16944
17184
17184
17200
Actions #1

Updated by peterzhu2118 (Peter Zhu) about 9 hours ago

  • Status changed from Open to Closed

Applied in changeset git|10574857ce167869524b97ee862b610928f6272f.


Fix memory leak in Regexp capture group when timeout

[Bug #20650]

The capture group allocates memory that is leaked when it times out.

For example:

re = Regexp.new("^#{"(a*)" * 10_000}x$", timeout: 0.000001)
str = "a" * 1000000 + "x"

10.times do
  100.times do
    re =~ str
  rescue Regexp::TimeoutError
  end

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

Before:

34688
56416
78288
100368
120784
140704
161904
183568
204320
224800

After:

16288
16288
16880
16896
16912
16928
16944
17184
17184
17200

Updated by peterzhu2118 (Peter Zhu) about 9 hours ago

  • Backport changed from 3.1: UNKNOWN, 3.2: REQUIRED, 3.3: REQUIRED to 3.1: UNKNOWN, 3.2: WONTFIX, 3.3: REQUIRED

I opened a Ruby 3.3 backport here: https://github.com/ruby/ruby/pull/11244

Actions

Also available in: Atom PDF

Like0
Like0Like0