Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: attempt to copy freed scalar #15086

Closed
p5pRT opened this issue Dec 10, 2015 · 6 comments
Closed

panic: attempt to copy freed scalar #15086

p5pRT opened this issue Dec 10, 2015 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 10, 2015

Migrated from rt.perl.org#126872 (status was 'rejected')

Searchable as RT126872$

@p5pRT
Copy link
Author

p5pRT commented Dec 10, 2015

From @KES777

Created by @KES777

$ perl -d​:KillPrint -e 0
panic​: attempt to copy freed scalar 2175990 to 2175600 at /home/kes/work/projects/perl_libs/Devel/DebugHooks.pm line 17.
BEGIN failed--compilation aborted.

$cat Devel/KillPrint.pm
package Devel​::KillPrint;

our $VERSION = '0.01';

sub import {
}

use Devel​::DebugHooks;

1;

$cat Devel/DebugHooks.pm
package Devel​::DebugHooks;

our $VERSION = '0.01';

sub import {
}

package # hide the package from the PAUSE indexer
  DB;

sub frames {
  my $level = shift;
  return ( [ @​DB​::args ], caller( $level +1 ) ) if defined $level;
}

sub DB {
}

sub trace_subs {
  my $level = 0;

  my( $args, @​frame ) = DB​::frames( $level );
}

sub sub {
  trace_subs;
  return &$DB​::sub;
};

1;

PS. This were another tuturial question.

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.22.0:

Configured by kes at Tue Sep 29 16:12:55 EEST 2015.

Summary of my perl5 (revision 5 version 22 subversion 0) configuration:
   
  Platform:
    osname=linux, osvers=3.13.0-37-generic, archname=x86_64-linux
    uname='linux keswork 3.13.0-37-generic #64-ubuntu smp mon sep 22 21:28:38 utc 2014 x86_64 x86_64 x86_64 gnulinux '
    config_args='-des -Dprefix=/home/kes/perl'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.8.4', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.19.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.19'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'



@INC for perl 5.22.0:
    /home/kes/work/projects/perl_libs
    /home/kes/perl5/lib/perl5/x86_64-linux
    /home/kes/perl5/lib/perl5
    /home/kes/perl/lib/site_perl/5.22.0/x86_64-linux
    /home/kes/perl/lib/site_perl/5.22.0
    /home/kes/perl/lib/5.22.0/x86_64-linux
    /home/kes/perl/lib/5.22.0
    .


Environment for perl 5.22.0:
    HOME=/home/kes
    LANG=ru_UA.UTF-8
    LANGUAGE=en
    LC_MESSAGES=en_US.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/kes/perl/bin:/home/kes/perl/bin:/home/kes/perl5/bin:/home/kes/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
    PERL5DB=BEGIN { require "Devel/KillPrint.pm" }
    PERL5LIB=/home/kes/work/projects/perl_libs:/home/kes/perl5/lib/perl5
    PERLDB_OPTS=RemotePort=keswork:9001
    PERL_BADLANG (unset)
    PERL_MB_OPT=--install_base "/home/kes/perl5"
    PERL_MM_OPT=INSTALL_BASE=/home/kes/perl5
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Dec 10, 2015

From @KES777

if in sub frames I add line​:

sub frames {
  my $level = shift;
+my @​frame = caller( $level +1 );
  return ( [ @​DB​::args ], caller( $level +1 ) ) if defined $level;
}

In this case I do not get panic

@p5pRT
Copy link
Author

p5pRT commented Dec 10, 2015

From [Unknown Contact. See original ticket]

if in sub frames I add line​:

sub frames {
  my $level = shift;
+my @​frame = caller( $level +1 );
  return ( [ @​DB​::args ], caller( $level +1 ) ) if defined $level;
}

In this case I do not get panic

@p5pRT
Copy link
Author

p5pRT commented Dec 15, 2015

From @tonycoz

On Thu Dec 10 09​:24​:41 2015, kes-kes@​yandex.ua wrote​:

[Please describe your issue here]

$ perl -d​:KillPrint -e 0
panic​: attempt to copy freed scalar 2175990 to 2175600 at
/home/kes/work/projects/perl_libs/Devel/DebugHooks.pm line 17.
BEGIN failed--compilation aborted.

@​DB​::args is a very low-level copy of the subroutine arguments, it doesn't keep reference counts to those arguments, so if you use @​DB​::args when the sub call that was used to populate it has returned, its values are invalid.

Your code is attemptting to use values in @​DB​::args from the *previous* call to caller(), for which the subroutine has returned.

If you ensure caller() is called before you use @​DB​::args​:

sub frames {
  my $level = shift;
  my @​c = caller($level+1);
  return ( [ @​DB​::args ], @​c ) if defined $level;
}

there's no crash.

Tony

@p5pRT
Copy link
Author

p5pRT commented Dec 15, 2015

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Dec 17, 2015

@tonycoz - Status changed from 'open' to 'rejected'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant