develooper Front page | perl.perl5.porters | Postings from July 2016

[perl #128634] Unexpected: Use of freed value in iteration at ...

Thread Previous
From:
Father Chrysostomos via RT
Date:
July 16, 2016 17:19
Subject:
[perl #128634] Unexpected: Use of freed value in iteration at ...
Message ID:
rt-4.0.18-20098-1468689532-1107.128634-15-0@perl.org
On Sat Jul 16 10:00:14 2016, kes-kes@yandex.ru wrote:
> $ cat example.pl
> my $hash =  { a => {}, b =>  {} };
> for my $value ( values %$hash ) {
>     delete $hash->{ b };
>     print $value;  #<<<<< Use of freed value in iteration at ...
> }
> 
> $ perl example.pl
> Use of freed value in iteration at iter_free line 4.
> HASH(0x1590178)
> $ perl example.pl
> HASH(0x17e6d38)HASH(0x17d1178)
> 
> That is not expected to get different behavior for two runs
> 
> Maybe related to:
> https://rt.perl.org/Public/Bug/Display.html?id=85026 which was closed
> as of 5.14.1
> https://metacpan.org/pod/distribution/perl/pod/perl5141delta.pod#Bug-
> Fixes
>  * A bug has been fixed that would cause a "Use of freed value in
> iteration"
>    error if the next two hash elements that would be iterated over are
> deleted. [perl #85026]

No, it’s not related to that.


> https://rt.perl.org/Public/Bug/Display.html?id=89548
> https://rt.perl.org/Public/Bug/Display.html?id=77706

That’s exactly it.  The stack holds no reference counts and ‘delete $hash->{b}’ frees one of the return values of ‘values’ which is on the stack on items that ‘for’ is iterating through.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=128634

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About