]> git.vpit.fr Git - perl/modules/Test-Valgrind.git/commitdiff
Make sure the fake valgrind test executables are not opened when used rt108873
authorVincent Pit <perl@profvince.com>
Fri, 13 Nov 2015 12:46:44 +0000 (10:46 -0200)
committerVincent Pit <perl@profvince.com>
Fri, 13 Nov 2015 13:17:37 +0000 (11:17 -0200)
This fixes RT #108873.

t/lib/Test/Valgrind/FakeValgrind.pm

index ec3abd46aac292f2832cd687ffcb98b17a3ee513..71077bd65b8275cef5e74f9dc284edd76fedb2a0 100644 (file)
@@ -47,8 +47,15 @@ sub new {
   $self->{tmp_dir}      = $self->{tmp_dir_obj}->dirname;
   $self->{tmp_file}     = File::Spec->catfile($self->{tmp_dir}, $exe_name);
  } else {
   $self->{tmp_dir}      = $self->{tmp_dir_obj}->dirname;
   $self->{tmp_file}     = File::Spec->catfile($self->{tmp_dir}, $exe_name);
  } else {
-  $self->{tmp_file_obj} = File::Temp->new(UNLINK => 1);
-  $self->{tmp_file}     = $self->{tmp_file_obj}->filename;
+  # Can't use the OO interface if we don't wan't the file to be opened by
+  # default, but then we have to deal with cleanup ourselves.
+  (undef, my $tmp_file) = File::Temp::tempfile(
+   TEMPLATE => 'fakevgXXXX',
+   TMPDIR   => 1,
+   CLEANUP  => 0,
+   OPEN     => 0,
+  );
+  $self->{tmp_file}     = $tmp_file;
   my ($vol, $dir)       = File::Spec->splitpath($self->{tmp_file});
   $self->{tmp_dir}      = File::Spec->catpath($vol, $dir, '');
  }
   my ($vol, $dir)       = File::Spec->splitpath($self->{tmp_file});
   $self->{tmp_dir}      = File::Spec->catpath($vol, $dir, '');
  }
@@ -68,8 +75,10 @@ sub new {
  bless $self, $class;
 }
 
  bless $self, $class;
 }
 
-sub path { $_[0]->{tmp_file} }
+sub path    { $_[0]->{tmp_file} }
 
 
-sub dir  { $_[0]->{tmp_dir} }
+sub dir     { $_[0]->{tmp_dir} }
+
+sub DESTROY { 1 while unlink $_[0]->{tmp_file} }
 
 1;
 
 1;