This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH][BZ #15589] - freopen would close oldfd even though oldfd is same as newfd.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: lizhijian at cn dot fujitsu dot com
- Cc: libc-alpha at sourceware dot org
- Date: Sat, 21 Sep 2013 21:47:36 +0200
- Subject: [PATCH][BZ #15589] - freopen would close oldfd even though oldfd is same as newfd.
- Authentication-results: sourceware.org; auth=none
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);