Skip to content

Commit e7c6b0a

Browse files
committed
regcomp: ensure the RExC_state freed earlier rather than later
388bf71 (ignoring #23022 for now) ensured that the RExC_state and its controlled pointers were freed once and only once, regardless of whether re_op_compile() returned normally or threw an exception. Unfortunately that free could happen very later, surviving well beyond when the regexp was compiled. Add an ENTER/LEAVE pair to ensure the cleanup is done immediately on a normal return.
1 parent 8194f79 commit e7c6b0a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

regcomp.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,7 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
14811481
* or error. */
14821482
Newxz(pRExC_state, 1, RExC_state_t);
14831483

1484+
ENTER_with_name("re_op_compile");
14841485
SAVE_FREE_REXC_STATE(pRExC_state);
14851486

14861487
DEBUG_r({
@@ -1578,6 +1579,8 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
15781579
"Precompiled pattern%s\n",
15791580
orig_rx_flags & RXf_SPLIT ? " for split" : ""));
15801581

1582+
LEAVE_with_name("re_op_compile");
1583+
15811584
return (REGEXP*)re;
15821585
}
15831586
}
@@ -1593,7 +1596,9 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
15931596
pat = newSVpvn_flags(exp, plen, SVs_TEMP |
15941597
(IN_BYTES ? 0 : SvUTF8(pat)));
15951598
}
1596-
return CALLREGCOMP_ENG(eng, pat, orig_rx_flags);
1599+
REGEXP *re = CALLREGCOMP_ENG(eng, pat, orig_rx_flags);
1600+
LEAVE_with_name("re_op_compile");
1601+
return re;
15971602
}
15981603

15991604
/* ignore the utf8ness if the pattern is 0 length */
@@ -1643,6 +1648,7 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
16431648
Perl_re_printf( aTHX_ "%sSkipping recompilation of unchanged REx%s %s\n",
16441649
PL_colors[4], PL_colors[5], s);
16451650
});
1651+
LEAVE_with_name("re_op_compile");
16461652
return old_re;
16471653
}
16481654

@@ -2477,6 +2483,7 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
24772483
if (old_re && SvREADONLY(old_re))
24782484
SvREADONLY_on(Rx);
24792485
#endif
2486+
LEAVE_with_name("re_op_compile");
24802487
return Rx;
24812488
}
24822489

0 commit comments

Comments
 (0)