- pipe my $rdr, my $wtr or die "pipe(\$rdr, \$wtr): $!";
- my $pid = fork;
- if (!defined $pid) {
- die "fork(): $!";
- } elsif ($pid == 0) {
- setpgrp 0, 0 or die "setpgrp(0, 0): $!";
- close $rdr or die "close(\$rdr): $!";
- fcntl $wtr, F_SETFD, 0 or die "fcntl(\$wtr, F_SETFD, 0): $!";
- my @args = (
- '--tool=memcheck',
- '--leak-check=full',
- '--leak-resolution=high',
- '--num-callers=' . $callers,
- '--error-limit=yes',
- '--log-fd=' . fileno($wtr)
- );
- unless ($args{no_supp}) {
- for (Test::Valgrind::Suppressions::supp_path(), $args{supp}) {
- push @args, '--suppressions=' . $_ if $_;
- }
- }
- if (defined $args{extra} and ref $args{extra} eq 'ARRAY') {
- push @args, @{$args{extra}};
- }
- push @args, $^X;
- push @args, '-I' . $_ for @INC;
- push @args, '-MTest::Valgrind=run,1', $file;
- print STDERR "valgrind @args\n" if $args{diag};
- local $ENV{PERL_DESTRUCT_LEVEL} = 3;
- local $ENV{PERL_DL_NONLAZY} = 1;
- exec $vg, @args;
+ $run = 1;
+ return;
+ }
+
+ my ($file, $pm, $next);
+ my $l = 0;
+ while ($l < 1000) {
+ $next = (caller $l++)[1];
+ last unless defined $next;
+ next if $next eq '-e' or $next =~ /^\s*\(\s*eval\s*\d*\s*\)\s*$/ or !-f $next;
+ if ($next =~ /\.pm$/) {
+ $pm = $next;
+ } else {
+ $file = $next;