This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[libgfortran,committed] Fix an invalid free in cleanup function
- From: "François-Xavier Coudert" <fxcoudert at gmail dot com>
- To: "fortran at gcc dot gnu dot org List" <fortran at gcc dot gnu dot org>, "gcc-patches List" <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 19 Apr 2007 12:22:23 +0200
- Subject: [libgfortran,committed] Fix an invalid free in cleanup function
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; b=kDR6EoTLZs0KrJUvH4ceUGx+3pL/PoiVhPXd+yW/dB+HCeNrhKkA+tVncub3NpD6TJ2xZN+5ReCtZZz5eKci092J8G73rzVhXbAXFyQJTxbY2oj+fUFhTis4AuGg2w/nctU+PtEKTAS9up2qBa9NxHefvE8GK4He23DORzNDnSI=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type; b=P1LC5xN02gw3bvFcXLyi6GP9ysJgNRt7Oy1tyWoXMU01gWbEbCtFCq7ZiEQNSJ6iXuZOEYc9WsdwUH+TjxiSoakYJhgQAC2+HOxWSZpQdrLhNjB2nLNFG7t0y29mYI1v+EeS7VHCPWotLzgL5CGg1oEkfPZRepVjChRJuYqktFg=
I've had this in my tree for some time now, it fixes an invalid free
in libgfortran destructor function when the executable is called with
an absolute path (it was introduced by my -fbacktrace patch). It also
forces initialization of a temporary character buffer, used for a
getcwd() call.
Bootstrapped and regtesting on x86_64-linux. I'll commit when testing
is finished.
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.
Index: runtime/main.c
===================================================================
--- runtime/main.c (revision 123968)
+++ runtime/main.c (working copy)
@@ -97,6 +97,7 @@
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 @@
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 @@
cleanup (void)
{
close_units ();
+
+ if (please_free_exe_path_when_done)
+ free (exe_path);
}