On Tue, 17 Nov 2020 at 02:32, <perl-bug@ton.iguana.be> wrote: > > > This is a bug report for perl from perl-bug@ton.iguana.be, > generated with the help of perlbug 1.42 running under perl 5.30.3. > > > ----------------------------------------------------------------- > [Please describe your issue here] > > I reported it as a Carp bug, but there is some suspecious behaviour in the core > around @DB::args going on (see later in the report). > > The version of Carp on my system is 1.50 > > Consider the following program: > ======================== > #!/usr/bin/perl -l > package Foo; > use Carp; > > sub bar { > splice(@_, 0, 1); > # die "Boom!"; > croak "Boom!"; > } > > package main; > sub DESTROY { print "DESTROY" } > > { > my $obj = bless []; > eval { Foo::bar(undef, $obj)}; > print "ERR=$@"; > # @DB::args = (); > # eval { Carp::croak "zz" }; > } > print "END"; > ======================== > > It creates an obkect $obj inside a lexical scope. > This object should stop existing at the end of the scope, so it should print > "DESTROY". After that the program should print the last line and say "END" > > So we expect: > DESTROY > END > > We however get: > END > DESTROY > > The object survived until global destruction. > > Uncommenting any of the commented out lines will make the program work as > expected. Also commenting the "splice" statement will make things work. > > What is happening here is that the "croak" will call its internal "caller_info" > sub which will use caller() inside package DB to populate @DB::args. > (even though "croak" and "carp" mostly shouldn't need that). > > So the object ends up with an extra reference in @DB::args which makes it > survive to the end of the program. That is why clearing @DB::args or doing > another "croak" (which fill @DB::args with other data) fixes it. It also > explains why "die" instead of "croak" fixes this. This is an interesting bug. I do not think it really is in Carp, but rather in how @Db::args is set up, the array should be localized something like this: local *Db::args= \@_; So it should unwind when we exit the scope that the caller() was executed in I think. Maybe Carp should be armored against this for now however. YvesThread Previous