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

[patch] refcount re ops

Thread Next
From:
Doug MacEachern
Date:
August 3, 2001 18:16
Subject:
[patch] refcount re ops
Message ID:
Pine.LNX.4.21.0108031814240.23972-100000@mako.covalent.net
now that regexps are all properly freed, there is a possible segv since
re_dup points at the re optree and op_free is called on it more than once
when clones are destructed.  i'm not sure if sharing re optrees is thread
safe, but this patch stops the core dumping..

Index: sv.c
===================================================================
RCS file: /usr/local/cvs_repository/perl-current-mirror/sv.c,v
retrieving revision 1.1.1.70
diff -u -r1.1.1.70 sv.c
--- sv.c	2001/08/03 13:48:49	1.1.1.70
+++ sv.c	2001/08/04 01:13:06
@@ -8403,6 +8403,9 @@
 		ret->regstclass = (regnode*)d->data[i];
 		break;
 	    case 'o':
+		/* XXX: can this really be shared? */
+		d->data[i] = (void*)OpREFCNT_inc((OP*)r->data->data[i]);
+		break;
 	    case 'n':
 		d->data[i] = r->data->data[i];
 		break;
Index: regcomp.c
===================================================================
RCS file: /usr/local/cvs_repository/perl-current-mirror/regcomp.c,v
retrieving revision 1.1.1.28
diff -u -r1.1.1.28 regcomp.c
--- regcomp.c	2001/07/17 05:23:53	1.1.1.28
+++ regcomp.c	2001/08/04 01:12:20
@@ -2138,6 +2138,9 @@
 		    ENTER;
 		    Perl_save_re_context(aTHX);
 		    rop = sv_compile_2op(sv, &sop, "re", &av);
+		    sop->op_private |= OPpREFCOUNTED;
+		    /* re_dup will OpREFCNT_inc */
+		    OpREFCNT_set(sop, 1);
 		    LEAVE;
 
 		    n = add_data(pRExC_state, 3, "nop");
@@ -4609,7 +4612,11 @@
 		}
 		else
 		    PL_curpad = NULL;
-		op_free((OP_4tree*)r->data->data[n]);
+
+		if (!OpREFCNT_dec((OP_4tree*)r->data->data[n])) {
+                    op_free((OP_4tree*)r->data->data[n]);
+		}
+
 		PL_comppad = old_comppad;
 		PL_curpad = old_curpad;
 		SvREFCNT_dec((SV*)new_comppad);


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