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

* Re: [Patch, libfortran] PR47296 Segfault when running out of file descriptors
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Jerry DeLisle @ 2011-01-17  5:50 UTC (permalink / raw)
  To: Janne Blomqvist; +Cc: Fortran List, GCC Patches

On 01/16/2011 12:11 PM, Janne Blomqvist wrote:
> 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?
>

yes, this is fine.  Go ahead and commit.  I am still doing some testing on 
cygwin, but my initial tests are OK.  The only thing that has been holding me up 
is some build issues plus the time it takes to even try a build.

Thanks,

Jerry

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

* Re: [Patch, libfortran] PR47296 Segfault when running out of file descriptors
  2011-01-17  5:50 ` Jerry DeLisle
@ 2011-01-17  7:51   ` Janne Blomqvist
  0 siblings, 0 replies; 3+ messages in thread
From: Janne Blomqvist @ 2011-01-17  7:51 UTC (permalink / raw)
  To: Jerry DeLisle; +Cc: Fortran List, GCC Patches

On Mon, Jan 17, 2011 at 04:37, Jerry DeLisle <jvdelisle@frontier.com> wrote:
> On 01/16/2011 12:11 PM, Janne Blomqvist wrote:
>>
>> 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?
>>
>
> yes, this is fine.  Go ahead and commit.  I am still doing some testing on
> cygwin, but my initial tests are OK.  The only thing that has been holding
> me up is some build issues plus the time it takes to even try a build.

Sending        libgfortran/ChangeLog
Sending        libgfortran/io/unix.c
Transmitting file data ..
Committed revision 168888.

Thanks.


-- 
Janne Blomqvist

^ 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).