aboutsummaryrefslogtreecommitdiff
path: root/libgfortran/runtime/main.c
diff options
context:
space:
mode:
authorFrancois-Xavier Coudert <fxcoudert@gcc.gnu.org>2007-04-19 11:01:15 +0000
committerFrançois-Xavier Coudert <fxcoudert@gcc.gnu.org>2007-04-19 11:01:15 +0000
commita777d6e96715af95b710dc3fbd2f7ef3b5d7a767 (patch)
tree671c20848c6885bfd24842cb7c56a2b03340bd2f /libgfortran/runtime/main.c
parent8d5d5865293148f8208acdc962beb686a3836720 (diff)
downloadgcc-a777d6e96715af95b710dc3fbd2f7ef3b5d7a767.zip
gcc-a777d6e96715af95b710dc3fbd2f7ef3b5d7a767.tar.gz
gcc-a777d6e96715af95b710dc3fbd2f7ef3b5d7a767.tar.bz2
main.c (please_free_exe_path_when_done): New variable.
* 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. From-SVN: r123969
Diffstat (limited to 'libgfortran/runtime/main.c')
-rw-r--r--libgfortran/runtime/main.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/libgfortran/runtime/main.c b/libgfortran/runtime/main.c
index d40c6f6..e88c2ab 100644
--- a/libgfortran/runtime/main.c
+++ b/libgfortran/runtime/main.c
@@ -97,6 +97,7 @@ get_args (int *argc, char ***argv)
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. */
@@ -116,15 +117,18 @@ store_exe_path (const char * argv0)
if (argv0[0] == '/')
{
exe_path = argv0;
+ please_free_exe_path_when_done = 0;
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;
+ please_free_exe_path_when_done = 1;
}
/* Return the full path of the executable. */
@@ -168,4 +172,7 @@ static void __attribute__((destructor))
cleanup (void)
{
close_units ();
+
+ if (please_free_exe_path_when_done)
+ free (exe_path);
}