public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, libfortran] PR47296 Segfault when running out of file descriptors
@ 2011-01-16 20:56 Janne Blomqvist
  2011-01-17  5:50 ` Jerry DeLisle
  0 siblings, 1 reply; 3+ messages in thread
From: Janne Blomqvist @ 2011-01-16 20:56 UTC (permalink / raw)
  To: Fortran List, GCC Patches

[-- Attachment #1: Type: text/plain, Size: 443 bytes --]

Hello,

the attached patch fixes the PR, the reason for the segfault was that
even if opening a temporary file fails we still access the file name
info. Thus don't free it in the unix.c:tempfile() function; freeing
opp->file is taken care of by the cleanup in open.c:new_unit() which
is the only caller. Thus this does not cause a memory leak (checked
with valgrind).

Regtested on x86_64-unknown-linux-gnu, Ok for trunk?

-- 
Janne Blomqvist

[-- Attachment #2: ChangeLog --]
[-- Type: application/octet-stream, Size: 151 bytes --]

2011-01-16  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/47296
	* io/unix.c (tempfile): Set opp->file and opp->file_len also if an
	error occurs.

[-- Attachment #3: pr47296.diff --]
[-- Type: text/x-patch, Size: 549 bytes --]

diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c
index e66560f..f34ee63 100644
--- a/libgfortran/io/unix.c
+++ b/libgfortran/io/unix.c
@@ -1084,13 +1084,8 @@ tempfile (st_parameter_open *opp)
   while (fd == -1 && errno == EEXIST);
 #endif /* HAVE_MKSTEMP */
 
-  if (fd < 0)
-    free (template);
-  else
-    {
-      opp->file = template;
-      opp->file_len = strlen (template);	/* Don't include trailing nul */
-    }
+  opp->file = template;
+  opp->file_len = strlen (template);	/* Don't include trailing nul */
 
   return fd;
 }

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-01-17  5:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-16 20:56 [Patch, libfortran] PR47296 Segfault when running out of file descriptors Janne Blomqvist
2011-01-17  5:50 ` Jerry DeLisle
2011-01-17  7:51   ` Janne Blomqvist

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).