perl5
perl5 copied to clipboard
safer cleanup when failing to compile regexps
Prior to this commit when producing a warning the regexp compiler would check if the warning category was marked as FATAL, and if it was it would add clean up to the save stack to release buffers used during compilation and to release the working REGEXP SV.
This causes two type of problems:
-
if an error was already queued, Perl_ck_warner() returns even if the warning is fatal, this meant that the normal clean up code Perl_re_op_compile() would also run, resulting in a double free of the buffers.
-
without fatal warnings, if a $SIG{WARN} handler died, the buffers and the working REGEXP SV would leak.
Avoid this by using SAVEDESTRUCTOR_X() to release the memory and optionally the SV at the end of scope.
Fixes #21661
@tonycoz looks like this can be merged?
@tonycoz, this p.r. has had merge conflicts for close to 5 months. Do you intend to go forward with it? If not, please consider closing it. Thanks.
I've rebased the PR on top of blead and removed the conflicts. Unless someone objects (or beats me to the punch), I intend on merging this within a day or two.