fix buggy reference count on refs to SVs with autoviv magic
authorGurusamy Sarathy <gsar@cpan.org>
Sun, 25 Apr 1999 22:58:27 +0000 (22:58 +0000)
committerGurusamy Sarathy <gsar@cpan.org>
Sun, 25 Apr 1999 22:58:27 +0000 (22:58 +0000)
(resulted in C<my @a; $a[1] = 1; print \$_ for @a> and Data::Dumper
accessing free()d memory)

p4raw-id: //depot/perl@3270

pp.c
t/op/ref.t

diff --git a/pp.c b/pp.c
index 8c48574..e6a2e11 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -512,6 +512,8 @@ refto(SV *sv)
            vivify_defelem(sv);
        if (!(sv = LvTARG(sv)))
            sv = &PL_sv_undef;
+       else
+           SvREFCNT_inc(sv);
     }
     else if (SvPADTMP(sv))
        sv = newSVsv(sv);
index 1d70f9f..618cfcc 100755 (executable)
@@ -1,6 +1,6 @@
 #!./perl
 
-print "1..55\n";
+print "1..56\n";
 
 # Test glob operations.
 
@@ -271,14 +271,22 @@ print $$_,"\n";
     print "# good, didn't recurse\n";
 }
 
+# test if refgen behaves with autoviv magic
+
+{
+    my @a;
+    $a[1] = "ok 53\n";
+    print ${\$_} for @a;
+}
+
 # test global destruction
 
 package FINALE;
 
 {
-    $ref3 = bless ["ok 55\n"];         # package destruction
-    my $ref2 = bless ["ok 54\n"];      # lexical destruction
-    local $ref1 = bless ["ok 53\n"];   # dynamic destruction
+    $ref3 = bless ["ok 56\n"];         # package destruction
+    my $ref2 = bless ["ok 55\n"];      # lexical destruction
+    local $ref1 = bless ["ok 54\n"];   # dynamic destruction
     1;                                 # flush any temp values on stack
 }