From: Dave Mitchell Date: Fri, 23 Jul 2004 11:06:02 +0000 (+0000) Subject: [perl #30733] memory leak in array delete X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2c8ddff3c182e26372c9343750c9b3c45e438ca2;p=p5sagit%2Fp5-mst-13.2.git [perl #30733] memory leak in array delete av_delete() wasn't mortalizing the returned value p4raw-id: //depot/perl@23158 --- diff --git a/av.c b/av.c index 3eaeea8..bedd04b 100644 --- a/av.c +++ b/av.c @@ -864,6 +864,8 @@ Perl_av_delete(pTHX_ AV *av, I32 key, I32 flags) SvREFCNT_dec(sv); sv = Nullsv; } + else + sv = sv_2mortal(sv); return sv; } diff --git a/t/op/delete.t b/t/op/delete.t index 53212a1..ac4405c 100755 --- a/t/op/delete.t +++ b/t/op/delete.t @@ -1,6 +1,6 @@ #!./perl -print "1..37\n"; +print "1..38\n"; # delete() on hash elements @@ -129,3 +129,16 @@ print @{$refary[0]} == 1 ? "ok 35\n" : "not ok 35 @list\n"; print "not " if defined $y; print "ok 37\n"; } + +{ + # [perl #30733] array delete didn't free returned element + my $x = 0; + sub X::DESTROY { $x++ } + { + my @a; + $a[0] = bless [], 'X'; + my $y = delete $a[0]; + } + print "not " unless $x == 1; + print "ok 38\n"; +}