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. */
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. */
cleanup (void)
{
close_units ();
+
+ if (please_free_exe_path_when_done)
+ free (exe_path);
}