On Fri, Apr 29, 2011 at 02:21:40AM -0700, perlbug@plan9.de wrote:
> # New Ticket Created by perlbug@plan9.de
> # Please include the string: [perl #89548]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=89548 >
>
>
>
> This is a bug report for perl from perlbug@plan9.de,
> generated with the help of perlbug 1.39 running under perl 5.12.3.
>
>
> -----------------------------------------------------------------
> [Please describe your issue here]
>
> It seems "for" does not keep references to the values it iterates over.
>
> The following script fails with "Use of freed value in iteration at ... line 6":
>
> my $a = my $b = { 1 => 1, 2 => 2 };
>
> for (values %$a, values %$b) {
> %$b=();
> }
>
> The expected result would be no output (and 4 iterations).
>
> This is especially problematic as for cannot even detect this case
> reliably, causing any amount of corruption.
>
The values entry in perlfunc says that values returned by C<< values >>
aren't copied; you get aliases. Considering that you wipe out %$b before
it's going to iterate over its values, bad things are bound to happen.
A work-around:
for (@{[values %$a, values %$b]}) {
%$b=();
}
which forces copying the values.
Abigail
Thread Previous
|
Thread Next