mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
Fix memory leak in String#start_with? when regexp times out
[Bug #20653] This commit refactors how Onigmo handles timeout. Instead of raising a timeout error, onig_search will return a ONIGERR_TIMEOUT which the caller can free memory, and then raise a timeout error. This fixes a memory leak in String#start_with when the regexp times out. For example: regex = Regexp.new("^#{"(a*)" * 10_000}x$", timeout: 0.000001) str = "a" * 1000000 + "x" 10.times do 100.times do str.start_with?(regex) rescue end puts `ps -o rss= -p #{$$}` end Before: 33216 51936 71152 81728 97152 103248 120384 133392 133520 133616 After: 14912 15376 15824 15824 16128 16128 16144 16144 16160 16160
This commit is contained in:
parent
67e1ea0028
commit
7464514ca5
Notes:
git
2024-07-26 12:42:57 +00:00
4 changed files with 32 additions and 54 deletions
4
regint.h
4
regint.h
|
@ -163,9 +163,6 @@
|
|||
rb_thread_check_ints(); \
|
||||
} \
|
||||
} while(0)
|
||||
# define HANDLE_REG_TIMEOUT_IN_MATCH_AT do { \
|
||||
rb_reg_raise_timeout(); \
|
||||
} while (0)
|
||||
# define onig_st_init_table st_init_table
|
||||
# define onig_st_init_table_with_size st_init_table_with_size
|
||||
# define onig_st_init_numtable st_init_numtable
|
||||
|
@ -1002,7 +999,6 @@ extern int onig_st_insert_strend(hash_table_type* table, const UChar* str_key, c
|
|||
extern size_t onig_memsize(const regex_t *reg);
|
||||
extern size_t onig_region_memsize(const struct re_registers *regs);
|
||||
bool rb_reg_timeout_p(regex_t *reg, void *end_time);
|
||||
NORETURN(void rb_reg_raise_timeout(void));
|
||||
#endif
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue