Skip to content

Commit d0d8d0c

Browse files
committed
PATCH: [perl #133642] Double free
This was caused by doing a SAVEFREEPV twice. The solution is to not do this twice. But this means that if the process unexpectedly dies, there is a potential memory leak. That potential already exists with other variables, and has its own ticket #133589.
1 parent 537657c commit d0d8d0c

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

regcomp.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7533,15 +7533,6 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
75337533

75347534
SetProgLen(RExC_rxi,RExC_size);
75357535

7536-
/* The values for the two variables below are now immutable, we can add
7537-
* them to the list to free without overwhelming it */
7538-
if (RExC_open_parens) {
7539-
SAVEFREEPV(RExC_open_parens);
7540-
}
7541-
if (RExC_close_parens) {
7542-
SAVEFREEPV(RExC_close_parens);
7543-
}
7544-
75457536
/* Update the string to compile, with correct modifiers, etc */
75467537
set_regex_pv(pRExC_state, Rx);
75477538

@@ -8094,6 +8085,15 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
80948085
});
80958086
#endif
80968087

8088+
if (RExC_open_parens) {
8089+
Safefree(RExC_open_parens);
8090+
RExC_open_parens = NULL;
8091+
}
8092+
if (RExC_close_parens) {
8093+
Safefree(RExC_close_parens);
8094+
RExC_close_parens = NULL;
8095+
}
8096+
80978097
#ifdef USE_ITHREADS
80988098
/* under ithreads the ?pat? PMf_USED flag on the pmop is simulated
80998099
* by setting the regexp SV to readonly-only instead. If the

t/re/pat.t

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ BEGIN {
2323
skip_all('no re module') unless defined &DynaLoader::boot_DynaLoader;
2424
skip_all_without_unicode_tables();
2525

26-
plan tests => 849; # Update this when adding/deleting tests.
26+
plan tests => 850; # Update this when adding/deleting tests.
2727

2828
run_tests() unless caller;
2929

@@ -1950,6 +1950,9 @@ EOP
19501950
{ # [perl $132164]
19511951
fresh_perl_is('m m0*0+\Rm', "",{},"Undefined behavior in address sanitizer");
19521952
}
1953+
{ # [perl #133642]
1954+
fresh_perl_is('m/((?<=(0?)))/', "Variable length lookbehind not implemented in regex m/((?<=(0?)))/ at - line 1.",{},"Was getting 'Double free'");
1955+
}
19531956

19541957
} # End of sub run_tests
19551958

0 commit comments

Comments
 (0)