develooper Front page | perl.perl5.porters | Postings from August 2001

[patch] ignore PL_curpm in PL_regex_padav cleanup

Thread Next
From:
Doug MacEachern
Date:
August 3, 2001 17:36
Subject:
[patch] ignore PL_curpm in PL_regex_padav cleanup
Message ID:
Pine.LNX.4.21.0108031730040.23972-100000@mako.covalent.net
this part of the regex plug patch was indeed bogus:
            if (re && (re->refcnt > 0)) {
                ReREFCNT_dec(re);
            }

it was a bandaid since some refcnts were dropping below 0, in which case
Perl_pregfree would try to free them again.  turns out that case is
PL_curpm, which is just a pointer, the real thing gets freed elsewhere.
patch fixes by marking the PL_regex_padav entry for PL_curpm with the
SVf_BREAK flag.  the flag is only used until arena cleanup, which happens
after PL_regex_padav has already been cleared.

Index: perl.c
===================================================================
RCS file: /usr/local/cvs_repository/perl-current-mirror/perl.c,v
retrieving revision 1.1.1.42
diff -u -r1.1.1.42 perl.c
--- perl.c	2001/08/03 13:48:47	1.1.1.42
+++ perl.c	2001/08/04 00:25:54
@@ -477,8 +477,16 @@
         SV **ary = AvARRAY(PL_regex_padav);
 
         while (i) {
-            REGEXP *re = (REGEXP *)SvIVX(ary[--i]);
-            if (re && (re->refcnt > 0)) {
+            SV *resv = ary[--i];
+            REGEXP *re = (REGEXP *)SvIVX(resv);
+
+            if (SvFLAGS(resv) & SVf_BREAK) {
+                /* this is PL_curpm, already freed
+                 * flag is set in regexec.c:S_regtry
+                 */
+                SvFLAGS(resv) &= ~SVf_BREAK;
+            }
+            else {
                 ReREFCNT_dec(re);
             }
         }
Index: regexec.c
===================================================================
RCS file: /usr/local/cvs_repository/perl-current-mirror/regexec.c,v
retrieving revision 1.1.1.25
diff -u -r1.1.1.25 regexec.c
--- regexec.c	2001/07/23 17:52:25	1.1.1.25
+++ regexec.c	2001/08/04 00:25:04
@@ -1855,6 +1855,8 @@
 #ifdef USE_ITHREADS
             {
                 SV* repointer = newSViv(0);
+                /* so we know which PL_regex_padav element is PL_curpm */
+                SvFLAGS(repointer) |= SVf_BREAK;
                 av_push(PL_regex_padav,repointer);
                 PL_reg_curpm->op_pmoffset = av_len(PL_regex_padav);
                 PL_regex_pad = AvARRAY(PL_regex_padav);


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About