This file is indexed.

/usr/share/perl5/Test/Valgrind/Command/Perl.pm is in libtest-valgrind-perl 1.19-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
package Test::Valgrind::Command::Perl;

use strict;
use warnings;

=head1 NAME

Test::Valgrind::Command::Perl - A Test::Valgrind command that invokes perl.

=head1 VERSION

Version 1.19

=cut

our $VERSION = '1.19';

=head1 DESCRIPTION

This command is the base for all C<perl>-based commands.
It handles the suppression generation and sets the main command-line flags.

=cut

use List::Util    ();
use Env::Sanctify ();

use Test::Valgrind::Suppressions;

use base qw<Test::Valgrind::Command Test::Valgrind::Carp>;

=head1 METHODS

This class inherits L<Test::Valgrind::Command>.

=head2 C<new>

    my $tvcp = Test::Valgrind::Command::Perl->new(
     perl       => $^X,
     inc        => \@INC,
     taint_mode => $taint_mode,
     %extra_args,
    );

The package constructor, which takes several options :

=over 4

=item *

The C<perl> option specifies which C<perl> executable will run the argument list given in C<args>.

Defaults to C<$^X>.

=item *

C<inc> is a reference to an array of paths that will be passed as C<-I> to the invoked command.

Defaults to C<@INC>.

=item *

C<$taint_mode> is a boolean that specifies if the script should be run under taint mode.

Defaults to false.

=back

Other arguments are passed straight to C<< Test::Valgrind::Command->new >>.

=cut

sub new {
 my $class = shift;
 $class = ref($class) || $class;

 my %args = @_;

 my $perl       = delete $args{perl} || $^X;
 my $inc        = delete $args{inc}  || [ @INC ];
 $class->_croak('Invalid INC list') unless ref $inc eq 'ARRAY';
 my $taint_mode = delete $args{taint_mode};

 my $trainer_file = delete $args{trainer_file};

 my $self = bless $class->SUPER::new(%args), $class;

 $self->{perl}       = $perl;
 $self->{inc}        = $inc;
 $self->{taint_mode} = $taint_mode;

 $self->{trainer_file} = $trainer_file;

 return $self;
}

sub new_trainer {
 my $self = shift;

 require File::Temp;
 my ($fh, $file) = File::Temp::tempfile(UNLINK => 0);
 {
  my $curpos = tell DATA;
  print $fh $_ while <DATA>;
  seek DATA, $curpos, 0;
 }
 close $fh or $self->_croak("close(tempscript): $!");

 $self->new(
  args         => [ '-MTest::Valgrind=run,1', $file ],
  trainer_file => $file,
  @_
 );
}

=head2 C<perl>

    my $perl = $tvcp->perl;

Read-only accessor for the C<perl> option.

=cut

sub perl { $_[0]->{perl} }

=head2 C<inc>

    my @inc = $tvcp->inc;

Read-only accessor for the C<inc> option.

=cut

sub inc { @{$_[0]->{inc} || []} }

=head2 C<taint_mode>

    my $taint_mode = $tvcp->taint_mode;

Read-only accessor for the C<taint_mode> option.

=cut

sub taint_mode { $_[0]->{taint_mode} }

sub args {
 my $self = shift;

 return $self->perl,
        (('-T') x!! $self->taint_mode),
        map("-I$_", $self->inc),
        $self->SUPER::args(@_);
}

=head2 C<env>

    my $env = $tvcp->env($session);

Returns an L<Env::Sanctify> object that sets the environment variables C<PERL_DESTRUCT_LEVEL> to C<3> and C<PERL_DL_NONLAZY> to C<1> during the run.

=cut

sub env {
 Env::Sanctify->sanctify(
  env => {
   PERL_DESTRUCT_LEVEL => 3,
   PERL_DL_NONLAZY     => 1,
  },
 );
}

sub suppressions_tag {
 my ($self) = @_;

 unless (defined $self->{suppressions_tag}) {
  my $env = Env::Sanctify->sanctify(sanctify => [ qr/^PERL/ ]);

  open my $pipe, '-|', $self->perl, '-V'
                     or $self->_croak('open("-| ' . $self->perl . " -V\"): $!");
  my $perl_v = do { local $/; <$pipe> };
  close $pipe or $self->_croak('close("-| ' . $self->perl . " -V\"): $!");

  require Digest::MD5;
  $self->{suppressions_tag} = Digest::MD5::md5_hex($perl_v);
 }

 return $self->{suppressions_tag};
}

sub check_suppressions_file {
 my ($self, $file) = @_;

 {
  open my $fh, '<', $file or return 0;

  local $_;
  while (<$fh>) {
   return 1 if /^\s*fun:(Perl|S|XS)_/
            or /^\s*obj:.*perl/;
  }

  close $fh;
 }

 return 0;
}

sub filter {
 my ($self, $session, $report) = @_;

 return $report if $report->is_diag
                or not $report->isa('Test::Valgrind::Report::Suppressions');

 my @frames = grep length, split /\n/, $report->data;

 # If we see the runloop, match from here.
 my $top = List::Util::first(sub {
  $frames[$_] =~ /^\s*fun:Perl_runops_(?:standard|debug)\b/
 }, 0 .. $#frames);
 --$top if $top;

 unless (defined $top) {
  # Otherwise, match from the latest Perl_ symbol.
  $top = List::Util::first(sub {
   $frames[$_] =~ /^\s*fun:Perl_/
  }, reverse 0 .. $#frames);
 }

 unless (defined $top) {
  # Otherwise, match from the latest S_ symbol.
  $top = List::Util::first(sub {
   $frames[$_] =~ /^\s*fun:S_/
  }, reverse 0 .. $#frames);
 }

 unless (defined $top) {
  # Otherwise, match from the latest XS_ symbol.
  $top = List::Util::first(sub {
   $frames[$_] =~ /^\s*fun:XS_/
  }, reverse 0 .. $#frames);
 }

 $#frames = $top if defined $top;

 my $data = join "\n", @frames, '';

 $data = Test::Valgrind::Suppressions->maybe_generalize($session, $data);

 $report->new(
  id   => $report->id,
  kind => $report->kind,
  data => $data,
 );
}

sub DESTROY {
 my ($self) = @_;

 my $file = $self->{trainer_file};
 return unless $file and -e $file;

 1 while unlink $file;

 return;
}

=head1 SEE ALSO

L<Test::Valgrind>, L<Test::Valgrind::Command>.

L<Env::Sanctify>.

=head1 AUTHOR

Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.

You can contact me by mail or on C<irc.perl.org> (vincent).

=head1 BUGS

Please report any bugs or feature requests to C<bug-test-valgrind at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Valgrind>.
I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Test::Valgrind::Command::Perl

=head1 COPYRIGHT & LICENSE

Copyright 2009,2010,2011,2013,2015,2016 Vincent Pit, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

=cut

1; # End of Test::Valgrind::Command::Perl

__DATA__
use strict;
use warnings;

BEGIN { require Test::Valgrind; }

use Test::More;

eval {
 require XSLoader;
 XSLoader::load('Test::Valgrind', $Test::Valgrind::VERSION);
};

if ($@) {
 diag $@;
 *Test::Valgrind::DEBUGGING = sub { 'unknown' };
} else {
 Test::Valgrind::notleak("valgrind it!");
}

plan tests => 1;
fail 'should not be seen';
diag 'debbugging flag is ' . Test::Valgrind::DEBUGGING();

eval {
 require XSLoader;
 XSLoader::load('Test::Valgrind::Fake', 0);
};

diag $@ ? 'Ok' : 'Succeeded to load Test::Valgrind::Fake but should\'t';

require List::Util;

my @cards = List::Util::shuffle(0 .. 51);

{
 package Test::Valgrind::Test::Fake;

 use base qw<strict>;
}

eval 'use Time::HiRes qw<usleep>';