summaryrefslogtreecommitdiff
path: root/regexec.c
diff options
authorPeter Zhu <[email protected]>2024-01-30 14:15:56 -0500
committerPeter Zhu <[email protected]>2024-02-02 10:39:42 -0500
commit1c120efe02d079b0a1dea573cf0fd7978d9cc857 (patch)
tree137c02f71f262d8368098dc47f0b87fb024eab7a /regexec.c
parenta4e4e3b1f1bd66ce9121c0ba2a1926e2459106dc (diff)
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.
Diffstat (limited to 'regexec.c')
-rw-r--r--regexec.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/regexec.c b/regexec.c
index 150d36ccc8..81d0ea6a6b 100644
--- a/regexec.c
+++ b/regexec.c
@@ -2293,7 +2293,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
UChar *pkeep;
char *alloca_base;
char *xmalloc_base = NULL;
- OnigStackType *stk_alloc, *stk_base, *stk, *stk_end;
+ OnigStackType *stk_alloc, *stk_base = NULL, *stk, *stk_end;
OnigStackType *stkp; /* used as any purpose. */
OnigStackIndex si;
OnigStackIndex *repeat_stk;
@@ -4202,6 +4202,11 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
STACK_SAVE;
xfree(xmalloc_base);
return ONIGERR_UNEXPECTED_BYTECODE;
+
+ timeout:
+ xfree(xmalloc_base);
+ xfree(stk_base);
+ HANDLE_REG_TIMEOUT_IN_MATCH_AT;
}