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

[patch] plug PL_regex_padav leaks

Thread Next
From:
Doug MacEachern
Date:
August 2, 2001 20:23
Subject:
[patch] plug PL_regex_padav leaks
Message ID:
Pine.LNX.4.21.0108022020100.8991-100000@mako.covalent.net
this patch plugs a massive leak, REGEXPs were only freed in the parent
interpreter (see comment in perl.c hunk).  still not the last of the
leaks, but getting closer..

Index: op.c
===================================================================
RCS file: /usr/local/cvs_repository/perl-current-mirror/op.c,v
retrieving revision 1.1.1.55
diff -u -r1.1.1.55 op.c
--- op.c	2001/08/02 03:15:44	1.1.1.55
+++ op.c	2001/08/03 03:18:16
@@ -852,8 +852,14 @@
 #endif
 	}
 	cPMOPo->op_pmreplroot = Nullop;
-	ReREFCNT_dec(PM_GETRE(cPMOPo));
-	PM_SETRE(cPMOPo, (REGEXP*)NULL);
+        /* we use the "SAFE" version of the PM_ macros here
+         * since sv_clean_all might release some PMOPs
+         * after PL_regex_padav has been cleared
+         * and the clearing of PL_regex_padav needs to
+         * happen before sv_clean_all
+         */
+	ReREFCNT_dec(PM_GETRE_SAFE(cPMOPo));
+	PM_SETRE_SAFE(cPMOPo, (REGEXP*)NULL);
 	break;
     }
 
Index: op.h
===================================================================
RCS file: /usr/local/cvs_repository/perl-current-mirror/op.h,v
retrieving revision 1.1.1.15
diff -u -r1.1.1.15 op.h
--- op.h	2001/07/12 23:14:04	1.1.1.15
+++ op.h	2001/08/03 03:18:21
@@ -252,9 +252,13 @@
 #ifdef USE_ITHREADS
 #define PM_GETRE(o)     ((REGEXP*)SvIVX(PL_regex_pad[(o)->op_pmoffset]))
 #define PM_SETRE(o,r)   (sv_setiv(PL_regex_pad[(o)->op_pmoffset], (IV)r))
+#define PM_GETRE_SAFE(o) (PL_regex_pad ? PM_GETRE(o) : (REGEXP*)0)
+#define PM_SETRE_SAFE(o,r) if (PL_regex_pad) PM_SETRE(o,r)
 #else
 #define PM_GETRE(o)     ((o)->op_pmregexp)
 #define PM_SETRE(o,r)   ((o)->op_pmregexp = (r))
+#define PM_GETRE_SAFE PM_GETRE
+#define PM_SETRE_SAFE PM_SETRE
 #endif
 
 #define PMdf_USED	0x01		/* pm has been used once already */
Index: perl.c
===================================================================
RCS file: /usr/local/cvs_repository/perl-current-mirror/perl.c,v
retrieving revision 1.1.1.41
diff -u -r1.1.1.41 perl.c
--- perl.c	2001/08/02 00:52:57	1.1.1.41
+++ perl.c	2001/08/03 03:18:25
@@ -466,6 +466,28 @@
     }
 #endif
 
+#ifdef USE_ITHREADS
+    /* the syntax tree is shared between clones
+     * so op_free(PL_main_root) only ReREFCNT_dec's
+     * REGEXPs in the parent interpreter
+     * we need to manually ReREFCNT_dec for the clones
+     */
+    {
+        I32 i = AvFILLp(PL_regex_padav) + 1;
+        SV **ary = AvARRAY(PL_regex_padav);
+
+        while (i) {
+            REGEXP *re = (REGEXP *)SvIVX(ary[--i]);
+            if (re && (re->refcnt > 0)) {
+                ReREFCNT_dec(re);
+            }
+        }
+    }
+    SvREFCNT_dec(PL_regex_padav);
+    PL_regex_padav = Nullav;
+    PL_regex_pad = NULL;
+#endif
+
     /* loosen bonds of global variables */
 
     if(PL_rsfp) {


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