This queue is for tickets about the Carp CPAN distribution.

Report information
The Basics
Id:
72467
Status:
open
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
sewi [...] cpan.org
Cc:
TEAM [...] cpan.org
ether [...] cpan.org
gregoa [...] cpan.org
AdminCc:

BugTracker
Severity:
Important
Broken in:
  • 1.22
  • 1.23
Fixed in:
(no value)



Subject: panic: attempt to copy freed scalar
perl -MCarp -le 'f(@ARGV); sub f { my $x = shift(@ARGV); carp($x)}' a v panic: attempt to copy freed scalar 183d588 to 1854078 at /usr/share/ perl/5.12/Carp.pm line 104. Carp's crash looses the original error message and all additional information. I don't know how, but Carp should catch this error and report everything which is possible.
Using $_[0]; in line 182 seems to fix the problem: # Transform an argument to a function into a string. sub format_arg { my $arg = $_[0]; shift; if ( ref($arg) ) { perl -I. -MCarp -le 'f(@ARGV); sub f { my $x = shift(@ARGV); carp($x)}' a v a at -e line 1 main::f(undef, 'v') called at -e line 1
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #72467] panic: attempt to copy freed scalar
Date: Sat, 19 Nov 2011 23:13:10 +0000
To: Sebastian Willing via RT <bug-Carp@rt.cpan.org>
From: Zefram <zefram@fysh.org>
Sebastian Willing via RT wrote:
Show quoted text
>Using $_[0]; in line 182 seems to fix the problem:
Not really, since you're getting undef rather than the actual argument. Getting undef consistently in place of a freed argument would be OK, but I think you're only getting undef by accident. There's obviously a core bug, possibly two, behind this. I've reported the two core issues as [perl #104074] and [perl #104076]. The former, involving @DB::args, may be merely a consequence of the latter, a simpler issue with freed sub args. In the latter, a missing sub arg certainly can be accidentally replaced by something other than undef. I'm going to wait until the core issue is understood before deciding what, if anything, Carp should do. Thanks for the report. -zefram
On Sat Nov 19 18:13:21 2011, zefram@fysh.org wrote:
Show quoted text
> > I'm going to wait until the core issue is understood before deciding what, > if anything, Carp should do.
It has been a long wait. I get "Bizarre copy of ARRAY" for which there's a concise summary at http://www.gossamer-threads.com/lists/perl/porters/227639 My band-aid is to turn this (in Carp.pm or Heavy.pm depending on version): my @args = map {Carp::format_arg($_)} @DB::args; Into this: my @args = eval { local $@; map {Carp::format_arg($_)} @DB::args; }; Then I at least get the sensible error that triggered carp/confess/etc. in the first place, and not the 'bizarre' error that tells me nothing useful.
On Fri Apr 13 19:53:19 2012, DOUGW wrote:
Show quoted text
> On Sat Nov 19 18:13:21 2011, zefram@fysh.org wrote:
> > > > I'm going to wait until the core issue is understood before deciding
what,
Show quoted text
> > if anything, Carp should do.
Show quoted text
> my @args = map {Carp::format_arg($_)} @DB::args; > > Into this: > > my @args = eval { > local $@; > map {Carp::format_arg($_)} @DB::args; > };
I think with the above fix you should at least be able to close the Carp bug, while keeping the many related bugs in perl itself open. Or maybe the eval belongs inside the map? (not tested): my @args = map { eval { local $@; Carp::format_arg($_) } } @DB::args; ??
On Sat Apr 14 13:53:47 2012, DOUGW wrote:
Show quoted text
> > my @args = map { eval { local $@; Carp::format_arg($_) } } @DB::args;
Die'ing inside the eval returns an empty array, so you lose an argument in @args. So even better so that you know you lost an argument (IMHO): @args = map { my $tmp = eval { Carp::format_arg($_) }; defined($tmp) ? $tmp : 'unknown'; } @DB::args;
On Wed Apr 18 11:34:19 2012, DOUGW wrote:
Show quoted text
> > @args = map { > my $tmp = eval { Carp::format_arg($_) }; > defined($tmp) ? $tmp : 'unknown'; > } @DB::args;
Forgot the local $@: @args = map { local $@; my $tmp = eval { Carp::format_arg($_) }; defined($tmp) ? $tmp : 'unknown'; } @DB::args;
A library that is supposed to report errors erroring out itself is a sad thing. Here is my fix to make the world a little less sad: my @args = map { local $@; my $tmp = eval { Carp::format_arg($_) }; defined($tmp) ? $tmp : 'unknown'; } @DB::args;
Seems to be still broken in 1.40 / Perl 5.24.0. [...] Checking if your kit is complete... Looks good ERROR from evaluation of /var/tmp/portage/net-analyzer/net-snmp-5.7.3-r5/work/net-snmp-5.7.3/perl/OID/Makefile.PL: panic: attempt to copy freed scalar 1221eb8 to 1b4e308 at /usr/lib64/perl5/5.24.0/Carp.pm line 229. Makefile:301: recipe for target 'perlmakefiles' failed [...]
Subject: Re: [rt.cpan.org #72467] panic: attempt to copy freed scalar
Date: Sun, 15 May 2016 20:36:52 +0100
To: bug-Carp@rt.cpan.org
From: Zefram <zefram@fysh.org>
Show quoted text
>Seems to be still broken in 1.40 / Perl 5.24.0.
Yes, and it's still only fixable in the perl core. -zefram
Simple test case in case one is still needed (the one at the beginning of this thread does not seem to trigger the error anymore): use Carp; Main(@ARGV); sub Main { my $first = shift @ARGV; $ARGV[0] = [qw(1 2 3)]; confess "Rubbish"; exit; }


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.