]> git.ipfire.org Git - thirdparty/make.git/commitdiff
* src/main.c: Ensure the stdin temp file is deleted when dying.
authorPaul Smith <psmith@gnu.org>
Sat, 26 Feb 2022 22:17:20 +0000 (17:17 -0500)
committerPaul Smith <psmith@gnu.org>
Sun, 27 Feb 2022 23:01:13 +0000 (18:01 -0500)
src/main.c

index 206e3b337057aaa7c8bf41df6df310c89e2a14d3..800591107f01eb62adca576d96527224495ec531 100644 (file)
@@ -296,6 +296,10 @@ char cmd_prefix = '\t';
 
 unsigned long command_count = 1;
 
+/* Remember the name of the batch file from stdin.  */
+
+static char *stdin_nm = 0;
+
 
 \f
 /* The usage output.  We write it this way to make life easier for the
@@ -1067,7 +1071,6 @@ int
 main (int argc, char **argv, char **envp)
 #endif
 {
-  static char *stdin_nm = 0;
   int makefile_status = MAKE_SUCCESS;
   struct goaldep *read_files;
   PATH_VAR (current_directory);
@@ -2595,6 +2598,8 @@ main (int argc, char **argv, char **envp)
   if (stdin_nm && unlink (stdin_nm) < 0 && errno != ENOENT)
     perror_with_name (_("unlink (temporary file): "), stdin_nm);
 
+  stdin_nm = NULL;
+
   /* If there were no command-line goals, use the default.  */
   if (goals == 0)
     {
@@ -3583,6 +3588,12 @@ die (int status)
       if (print_version_flag)
         print_version ();
 
+      /* Get rid of a temp file from reading a makefile from stdin.  */
+      if (stdin_nm && unlink (stdin_nm) < 0 && errno != ENOENT)
+        perror_with_name (_("unlink (temporary file): "), stdin_nm);
+
+      stdin_nm = NULL;
+
       /* Wait for children to die.  */
       err = (status != 0);
       while (job_slots_used > 0)