This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][BZ #15589] - freopen would close oldfd even though oldfd is same as newfd.


Hi, this is another bug with simple patch at bugzilla.

http://sourceware.org/bugzilla/show_bug.cgi?id=15589

This patch differs from original by replacing gotos by adding equivalent
if condition. 

Comments?

	* libio/freopen.c (freopen): Handle case when old descriptor is
	same as new one.
	* libio/freopen64.c (freopen64): Likewise.

diff --git a/libio/freopen.c b/libio/freopen.c
index 6ba37bf..7c3c112 100644
--- a/libio/freopen.c
+++ b/libio/freopen.c
@@ -79,7 +79,7 @@ freopen (filename, mode, fp)
       /* unbound stream orientation */
       result->_mode = 0;
 
-      if (fd != -1)
+      if (fd != -1 && _IO_fileno (result) != fd)
 	{
 #ifdef O_CLOEXEC
 # ifndef __ASSUME_DUP3
@@ -113,6 +113,7 @@ freopen (filename, mode, fp)
     }
   else if (fd != -1)
     __close (fd);
+
   if (filename == NULL)
     free ((char *) gfilename);
 
diff --git a/libio/freopen64.c b/libio/freopen64.c
index 660647e..59254a1 100644
--- a/libio/freopen64.c
+++ b/libio/freopen64.c
@@ -62,7 +62,7 @@ freopen64 (filename, mode, fp)
       /* unbound stream orientation */
       result->_mode = 0;
 
-      if (fd != -1)
+      if (fd != -1 && _IO_fileno (result) != fd)
 	{
 #ifdef O_CLOEXEC
 # ifndef __ASSUME_DUP3
@@ -96,6 +96,7 @@ freopen64 (filename, mode, fp)
     }
   else if (fd != -1)
     __close (fd);
+
   if (filename == NULL)
     free ((char *) gfilename);
   _IO_release_lock (fp);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]