OSDN Git Service

* runtime/main.c (please_free_exe_path_when_done): New variable.
authorfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 19 Apr 2007 11:01:15 +0000 (11:01 +0000)
committerfxcoudert <fxcoudert@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 19 Apr 2007 11:01:15 +0000 (11:01 +0000)
(store_exe_path): Initialize character buffer, and mark whether
exe_path should be free'd by the library destructor function.
(cleanup): Only free exe_path if needed.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@123969 138bc75d-0d04-0410-961f-82ee72b054a4

libgfortran/ChangeLog
libgfortran/runtime/main.c

index 3ce70e8..74ba4e0 100644 (file)
@@ -1,3 +1,10 @@
+2007-04-19  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
+
+       * runtime/main.c (please_free_exe_path_when_done): New variable.
+       (store_exe_path): Initialize character buffer, and mark whether
+       exe_path should be free'd by the library destructor function.
+       (cleanup): Only free exe_path if needed.
+
 2007-04-18  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
            Tobias Burnus  <burnus@net-b.de>
 
 2007-04-18  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
            Tobias Burnus  <burnus@net-b.de>
 
index d40c6f6..e88c2ab 100644 (file)
@@ -97,6 +97,7 @@ get_args (int *argc, char ***argv)
 
 
 static const char *exe_path;
 
 
 static const char *exe_path;
+static int please_free_exe_path_when_done;
 
 /* Save the path under which the program was called, for use in the
    backtrace routines.  */
 
 /* Save the path under which the program was called, for use in the
    backtrace routines.  */
@@ -116,15 +117,18 @@ store_exe_path (const char * argv0)
   if (argv0[0] == '/')
     {
       exe_path = argv0;
   if (argv0[0] == '/')
     {
       exe_path = argv0;
+      please_free_exe_path_when_done = 0;
       return;
     }
 
       return;
     }
 
+  memset (buf, 0, sizeof (buf));
   cwd = getcwd (buf, sizeof (buf));
 
   /* exe_path will be cwd + "/" + argv[0] + "\0" */
   path = malloc (strlen (cwd) + 1 + strlen (argv0) + 1);
   st_sprintf (path, "%s%c%s", cwd, DIR_SEPARATOR, argv0);
   exe_path = path;
   cwd = getcwd (buf, sizeof (buf));
 
   /* exe_path will be cwd + "/" + argv[0] + "\0" */
   path = malloc (strlen (cwd) + 1 + strlen (argv0) + 1);
   st_sprintf (path, "%s%c%s", cwd, DIR_SEPARATOR, argv0);
   exe_path = path;
+  please_free_exe_path_when_done = 1;
 }
 
 /* Return the full path of the executable.  */
 }
 
 /* Return the full path of the executable.  */
@@ -168,4 +172,7 @@ static void __attribute__((destructor))
 cleanup (void)
 {
   close_units ();
 cleanup (void)
 {
   close_units ();
+  
+  if (please_free_exe_path_when_done)
+    free (exe_path);
 }
 }