This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: ext/List/Util/t/weak.t panic
authorDave Mitchell <davem@fdisolutions.com>
Thu, 3 Jul 2003 01:32:11 +0000 (02:32 +0100)
committerJarkko Hietaniemi <jhi@iki.fi>
Thu, 3 Jul 2003 06:27:18 +0000 (06:27 +0000)
Message-ID: <20030703003211.GB3747@fdgroup.com>

p4raw-id: //depot/perl@19943

mg.c
sv.c

diff --git a/mg.c b/mg.c
index 1990b96..b69da05 100644 (file)
--- 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 (file)
--- 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);