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

DESTROY called twice on same object during global destruction. #13870

Open
p5pRT opened this issue May 22, 2014 · 1 comment
Open

DESTROY called twice on same object during global destruction. #13870

p5pRT opened this issue May 22, 2014 · 1 comment

Comments

@p5pRT
Copy link

p5pRT commented May 22, 2014

Migrated from rt.perl.org#121946 (status was 'new')

Searchable as RT121946$

@p5pRT
Copy link
Author

p5pRT commented May 22, 2014

From apm@one.com

Hi,

I've been having troubles with Perl calling the DESTROY method on my
objects twice (*in the same process*) during global destruction when the
Perl code forks. This happens often when using a module like
Net​::Server​::PreFork.

The problem has been reproduced on​:
Perl 5.10/Debian on Debian squeeze
Perl 5.14.2/Ubuntu on Ubuntu 12.04
Perl 5.18/Debian on Debian jessie
Perl 5.20-RC1 from upstream Perl

A colleague of mine was so kind to boil the steps to reproduce further
down to this snippet not using any modules​:

#!/usr/bin/perl

package MyModule;

use Devel​::Peek;

sub new {
print "IN NEW\n";
return bless {};
}

sub DESTROY {
print "======= BEGIN DESTROY​:".$$."========\n";
print Dump(@​_);
print "============ END DESTROY​:".$$."========\n";
}

1;

package main;

open my $fh, ">", "/tmp/some.pid";
print $fh $$;
close $fh;

my $hardtodestroy = new MyModule;
my $pid = fork;

if ($pid) {

print "Parent​: $$, child​: $pid\n";

$SIG{'TERM'} = sub { kill 15, $pid; exit 0; };
select undef,undef,undef, 300;

print "stopped\n";
kill 15, $pid;
exit 0;
}

$SIG{'TERM'} = sub { exit 0; };
select undef,undef,undef, 300;
exit 0;

Description​:

In one terminal run​:

$ while /bin/true ; perl destroybug.pl ; done

In another terminal run this​:

$ kill 15 -$(cat /tmp/some.pid)

Many times you will see the child calling destroy twice.

XS modules trying to use DESTROY to free() pointers kept in PVMG/IV
scalars will have free() called twice, causing glibc to complain.

regards,
Peter Mogensen

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

No branches or pull requests

2 participants