fill_packs_from_git: fix leaking of temporary files
authorOlev Kartau <olev.kartau@intel.com>
Thu, 10 Jul 2014 14:15:32 +0000 (17:15 +0300)
committerEd Bartosh <eduard.bartosh@intel.com>
Sun, 10 Aug 2014 08:26:46 +0000 (11:26 +0300)
In this function, all opened temporary files were left
undeleted and became garbage in /tmp.
CLEANUP is not valid flag for tempfile().
For tempfile, the flag would be UNLINK, but it can't be used
when OPEN is set to zero (which is the case).
Perl will not automatically delete such files,
so we have to close and delete them.

Change-Id: Id05ffa5c41f9d7522faa370fb8816ebb64740be6

depanneur

index b90d459987dfdf720a13e56393efbbc1ff930b4d..0f8ab62eed68b734e08df093a0d038c6a61d3b89 100755 (executable)
--- a/depanneur
+++ b/depanneur
@@ -553,8 +553,7 @@ sub fill_packs_from_git {
 
     debug("working on $base");
     if ($includeall == 0) {
-        # create temp file and desctroy it autoly
-        my (undef, $tmp_file) = tempfile(CLEANUP=>1, OPEN => 0);
+        my (undef, $tmp_file) = tempfile(OPEN => 0);
         if (my_system("cd $base; git show $spec_commit:$packaging_dir >$tmp_file 2>/dev/null") == 0) {
             open my $file, '<', $tmp_file or die $!;
             # the content like:
@@ -575,7 +574,7 @@ sub fill_packs_from_git {
                                       project_base_path => $base});
                 }
             } else {        #packaging_dir is a symbol link
-                my (undef, $tmp_symlink_file) = tempfile(CLEANUP=>1, OPEN => 0);
+                my (undef, $tmp_symlink_file) = tempfile(OPEN => 0);
                 # git show the real packaging dir
                 if (my_system("cd $base; git show $spec_commit:$first_line >$tmp_symlink_file 2>/dev/null") == 0) {
                     open my $symlink_file, '<', $tmp_symlink_file or die $!;
@@ -586,8 +585,12 @@ sub fill_packs_from_git {
                         push(@pre_packs, {filename => "$base/$first_line/$_",
                                           project_base_path => $base});
                     }
+                    close($symlink_file);
+                    unlink $tmp_symlink_file;
                 }
             }
+            close($file);
+            unlink $tmp_file;
         }
     } else {
         # specify --include-all use current packaging dir not from git