[perl #31851] Threading crash with closures
Dave Mitchell [Fri, 29 Oct 2004 21:04:17 +0000 (21:04 +0000)]
various OpREFCNT_inc() operations weren't doing locking

p4raw-id: //depot/perl@23433

pad.c
regcomp.c
sv.c

diff --git a/pad.c b/pad.c
index f1d15ab..0c00cff 100644 (file)
--- a/pad.c
+++ b/pad.c
@@ -1410,7 +1410,9 @@ Perl_cv_clone(pTHX_ CV *proto)
 #endif
     CvGV(cv)           = CvGV(proto);
     CvSTASH(cv)                = CvSTASH(proto);
+    OP_REFCNT_LOCK;
     CvROOT(cv)         = OpREFCNT_inc(CvROOT(proto));
+    OP_REFCNT_UNLOCK;
     CvSTART(cv)                = CvSTART(proto);
     CvOUTSIDE(cv)      = (CV*)SvREFCNT_inc(outside);
     CvOUTSIDE_SEQ(cv) = CvOUTSIDE_SEQ(proto);
index 7587498..2bcb16e 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -4983,9 +4983,14 @@ Perl_pregfree(pTHX_ struct regexp *r)
                    (SvTYPE(new_comppad) == SVt_PVAV) ?
                                new_comppad : Null(PAD *)
                );
+               OP_REFCNT_LOCK;
                if (!OpREFCNT_dec((OP_4tree*)r->data->data[n])) {
+                   OP_REFCNT_UNLOCK;
                     op_free((OP_4tree*)r->data->data[n]);
                }
+               else {
+                   OP_REFCNT_UNLOCK;
+               }
 
                PAD_RESTORE_LOCAL(old_comppad);
                SvREFCNT_dec((SV*)new_comppad);
diff --git a/sv.c b/sv.c
index f3575ad..69b9e2e 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -10244,7 +10244,9 @@ Perl_re_dup(pTHX_ REGEXP *r, CLONE_PARAMS *param)
            case 'o':
                /* Compiled op trees are readonly, and can thus be
                   shared without duplication. */
+               OP_REFCNT_LOCK;
                d->data[i] = (void*)OpREFCNT_inc((OP*)r->data->data[i]);
+               OP_REFCNT_UNLOCK;
                break;
            case 'n':
                d->data[i] = r->data->data[i];
@@ -10955,7 +10957,9 @@ Perl_sv_dup(pTHX_ SV *sstr, CLONE_PARAMS* param)
        Perl_rvpv_dup(aTHX_ dstr, sstr, param);
        CvSTASH(dstr)   = hv_dup(CvSTASH(sstr), param); /* NOTE: not refcounted */
        CvSTART(dstr)   = CvSTART(sstr);
+       OP_REFCNT_LOCK;
        CvROOT(dstr)    = OpREFCNT_inc(CvROOT(sstr));
+       OP_REFCNT_UNLOCK;
        CvXSUB(dstr)    = CvXSUB(sstr);
        CvXSUBANY(dstr) = CvXSUBANY(sstr);
        if (CvCONST(sstr)) {