This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[PATCH] Fortran: PR/34908, PR/36276: do not free current_file->filename if it changes
- From: "Laurynas Biveinis" <laurynas dot biveinis at gmail dot com>
- To: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Fri, 20 Jun 2008 14:30:53 +0200
- Subject: [PATCH] Fortran: PR/34908, PR/36276: do not free current_file->filename if it changes
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type:content-transfer-encoding :content-disposition; bh=uE6nz8TgfIfQ4YIynSuCUgMhWAd0VRN039aN9tlGTYw=; b=OX8XvpFa/VN60xrmnJRJqWEvaM2gho9KPH7Nbnpx55mKW0klaAte1v8nZQLS0f20/T cPOTU4kPOL95VmT5UlQ7p980mDtyqs6q7IxKWXWrbaUf5j7iM3oaT2Krn7UIKKKdZiSB UEoRbcRefNTm9vF33D+rrc/1HuTzepBSN+6ok=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition; b=u17FGRXpm+lgKT5tTJK3ToVt2Nt/AtP+AHlg8q4hrCe0zNIhVMD7quEA56H2M6F2A7 tm0hn2Wr8VI0l+aQHxDlv/l3Mayajr8+rY1sh0EMbDKPkBu+DaZ+x+PqHIs34QIMwgf/ yjsrDgqGn0TCLIinfNy+bK9VGKIt/Fux5psXQ=
Hi,
The "old" current_file->filename is referenced by linemap, thus it
cannot be freed at this point. The proper fix probably would be to
update linemap with the new filename, but in any case this trivial
patch is an improvement. This change is already suggested by a comment
in PR/36276, I arrived at it independently by investigating PR/34908.
Bootstrapped/regtested Fortran on trunk on x86_64-unknown-linux-gnu,
OK for trunk? OK for 4.3 branch after bootstrapping/regtesting there?
2008-06-20 Laurynas Biveinis <laurynas.biveinis@gmail.com>
PR fortran/34908, fortran/36276
* scanner.c (preprocessor_line): Do not call gfc_free for
current_file->filename if it differs from filename.
--
Laurynas
Index: gcc/fortran/scanner.c
===================================================================
--- gcc/fortran/scanner.c (revision 136912)
+++ gcc/fortran/scanner.c (working copy)
@@ -1654,7 +1654,9 @@
if (strcmp (current_file->filename, filename) != 0)
{
- gfc_free (current_file->filename);
+ /* FIXME: we leak the old filename because a pointer to it may be stored
+ in the linemap. Alternative could be using GC or updating linemap to
+ point to the new name, but there is no API for that currently. */
current_file->filename = gfc_getmem (strlen (filename) + 1);
strcpy (current_file->filename, filename);
}