Change 18554 by jhi@kosh on 2003/01/22 12:47:03
Subject: [PATCH av.c] Re: [perl #15439] unreferenced scalar due to double
DESTROY
From: Dave Mitchell <[EMAIL PROTECTED]>
Date: Sun, 19 Jan 2003 16:43:54 +0000
Message-ID: <[EMAIL PROTECTED]>
Affected files ...
... //depot/perl/av.c#71 edit
... //depot/perl/t/op/array.t#17 edit
Differences ...
==== //depot/perl/av.c#71 (text) ====
Index: perl/av.c
--- perl/av.c#70~17920~ Thu Sep 26 01:16:43 2002
+++ perl/av.c Wed Jan 22 04:47:03 2003
@@ -453,8 +453,11 @@
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))) {
==== //depot/perl/t/op/array.t#17 (xtext) ====
Index: perl/t/op/array.t
--- perl/t/op/array.t#16~9620~ Sat Apr 7 15:12:47 2001
+++ perl/t/op/array.t Wed Jan 22 04:47:03 2003
@@ -1,6 +1,12 @@
#!./perl
-print "1..72\n";
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+}
+
+print "1..73\n";
#
# @foo, @bar, and @ary are also used from tie-stdarray after tie-ing them
@@ -247,3 +253,22 @@
@tary = (0..50);
tary();
+
+
+require './test.pl';
+
+# bugid #15439 - clearing an array calls destructors which may try
+# to modify the array - caused 'Attempt to free unreferenced scalar'
+
+my $got = runperl (
+ prog => q{
+ sub X::DESTROY { @a = () }
+ @a = (bless {}, 'X');
+ @a = ();
+ },
+ stderr => 1
+ );
+
+$got =~ s/\n/ /g;
+print "# $got\nnot " unless $got eq '';
+print "ok 73\n";
End of Patch.