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

Re: panic+" Useless assignment to a temporary" errors in some buggycode in blead and other versions - is it a known problem?

Thread Previous | Thread Next
From:
Father Chrysostomos
Date:
July 7, 2016 04:58
Subject:
Re: panic+" Useless assignment to a temporary" errors in some buggycode in blead and other versions - is it a known problem?
Message ID:
20160707045828.6968.qmail@lists-nntp.develooper.com
I wrote:
> Shlomi Fish wrote:
> > Useless assignment to a temporary at panic-and-Useless-assignment.pl line 11.
> > Useless assignment to a temporary at panic-and-Useless-assignment.pl line 11.
> > panic: attempt to copy value 1 to a freed scalar 1e45c28 at
> > panic-and-Useless-assignment.pl line 11.
> > shlomif[ProjEuler]:~$
> >
> > and the program exits. Two questions:
> >
> > 1. Is it a known problem?
> >
> > 2. Why am I getting the warning? I am making use of $ret later on.
> 
> That does indeed appear to be a bug.  If I change //= to ||=, I can
> get the panic as far back as 5.8.9 and a crash in 5.8.8.  5.8.7 appears
> to be fine.
> 
> So maybe you could consider downgrading to 5.8.7. :-)
> 
> No, I do not know why it happens.

The usual 'stack not refcounted' bug.

You end up calling _cache recursively.  _cache in my slightly reduced version of your script is:

sub _cache
{
    my ($key, $promise) = @_;
    $cache{$key} ||= $promise->();
    %cache = ();
}

So %cache = () in the inner call frees $cache{$key} which is still on
the stack in the outer call.

The 'Useless assignment to a temporary' probably results from the
freed scalar having been reused for a temp scalar in the mean time.

It is the freed $cache{$key} that is being warned about, not your $ret
variable.

BTW, a bisect shows that it was already a problem in 5.8.0, but the
problem showed itself more readily after this commit:

29f4f0ab0cd22a86a6abeeb9b5de96d9506fd84a is the first bad commit
commit 29f4f0ab0cd22a86a6abeeb9b5de96d9506fd84a
Author: Nicholas Clark <nick@ccl4.org>
Date:   Wed Oct 18 17:35:06 2006 +0000

    panic if we attempt to sv_setsv to or from an already freed SV.


Thread Previous | Thread Next


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