10574857ce (master): Fix memory leak in Regexp capture group when timeout

0 views
Skip to first unread message

Peter Zhu

unread,
Jul 25, 2024, 9:24:04 AM (2 days ago) Jul 25
to ruby...@ruby-lang.org
Peter Zhu 2024-07-24 19:16:16 +0000 (Wed, 24 Jul 2024)

New Revision: 10574857ce

https://github.com/ruby/ruby/commit/10574857ce

Log:
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

Modified files:
include/ruby/onigmo.h
regexec.c
test/ruby/test_regexp.rb
Reply all
Reply to author
Forward
0 new messages