long %ENV values for VMS
[p5sagit/p5-mst-13.2.git] / av.c
diff --git a/av.c b/av.c
index acc9963..a000d46 100644 (file)
--- a/av.c
+++ b/av.c
@@ -1,6 +1,6 @@
 /*    av.c
  *
- *    Copyright (c) 1991-2002, Larry Wall
+ *    Copyright (c) 1991-2003, Larry Wall
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -453,8 +453,11 @@ Perl_av_clear(pTHX_ register AV *av)
        ary = AvARRAY(av);
        key = AvFILLp(av) + 1;
        while (key) {
-           SvREFCNT_dec(ary[--key]);
+           SV * sv = ary[--key];
+           /* undef the slot before freeing the value, because a
+            * destructor might try to modify this arrray */
            ary[key] = &PL_sv_undef;
+           SvREFCNT_dec(sv);
        }
     }
     if ((key = AvARRAY(av) - AvALLOC(av))) {