From: Dave Mitchell <davem@fdisolutions.com>
Date: Thu, 3 Jul 2003 01:32:11 +0000 (+0100)
Subject: Re: ext/List/Util/t/weak.t panic
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d99b02a1a9949639f16470065ea5568cd92f788d;p=p5sagit%2Fp5-mst-13.2.git

Re: ext/List/Util/t/weak.t panic
Message-ID: <20030703003211.GB3747@fdgroup.com>

p4raw-id: //depot/perl@19943
---

diff --git a/mg.c b/mg.c
index 1990b96..b69da05 100644
--- a/mg.c
+++ b/mg.c
@@ -1881,6 +1881,7 @@ Perl_magic_killbackrefs(pTHX_ SV *sv, MAGIC *mg)
 	}
 	i--;
     }
+    SvREFCNT_dec(av); /* remove extra count added by sv_add_backref() */
     return 0;
 }
 
diff --git a/sv.c b/sv.c
index 69fbbaa..76b1403 100644
--- a/sv.c
+++ b/sv.c
@@ -5091,7 +5091,9 @@ S_sv_add_backref(pTHX_ SV *tsv, SV *sv)
     else {
 	av = newAV();
 	sv_magic(tsv, (SV*)av, PERL_MAGIC_backref, NULL, 0);
-	SvREFCNT_dec(av);           /* for sv_magic */
+	/* av now has a refcnt of 2, which avoids it getting freed
+	 * before us during global cleanup. The extra ref is removed
+	 * by magic_killbackrefs() when tsv is being freed */
     }
     if (AvFILLp(av) >= AvMAX(av)) {
         SV **svp = AvARRAY(av);