mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
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.
This commit is contained in:
parent
a4e4e3b1f1
commit
1c120efe02
3 changed files with 31 additions and 12 deletions
16
re.c
16
re.c
|
@ -4605,8 +4605,8 @@ re_warn(const char *s)
|
|||
rb_hrtime_t rb_reg_match_time_limit = 0;
|
||||
|
||||
// This function is periodically called during regexp matching
|
||||
void
|
||||
rb_reg_check_timeout(regex_t *reg, void *end_time_)
|
||||
bool
|
||||
rb_reg_timeout_p(regex_t *reg, void *end_time_)
|
||||
{
|
||||
rb_hrtime_t *end_time = (rb_hrtime_t *)end_time_;
|
||||
|
||||
|
@ -4631,10 +4631,18 @@ rb_reg_check_timeout(regex_t *reg, void *end_time_)
|
|||
}
|
||||
else {
|
||||
if (*end_time < rb_hrtime_now()) {
|
||||
// timeout is exceeded
|
||||
rb_raise(rb_eRegexpTimeoutError, "regexp match timeout");
|
||||
// Timeout has exceeded
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
rb_reg_raise_timeout(void)
|
||||
{
|
||||
rb_raise(rb_eRegexpTimeoutError, "regexp match timeout");
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue