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 1/2] openpty: close slave pty fd on error


When openpty() failed only the master fd was closed so far. Let's close the
slave fd as well.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
---
 ChangeLog       | 4 ++++
 login/openpty.c | 4 +++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index bc1cf94dc3..bc5fb8e27f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-08-26  Christian Brauner  <christian.brauner@ubuntu.com>
+
+	* login/openpty.c (openpty): Close slave pty file descriptor on error.
+
 2017-08-25  H.J. Lu  <hongjiu.lu@intel.com>
 
 	* sysdeps/x86/cpu-features.h [__ASSEMBLER__]
diff --git a/login/openpty.c b/login/openpty.c
index 41ab0483e2..8fbc66a3ef 100644
--- a/login/openpty.c
+++ b/login/openpty.c
@@ -92,7 +92,7 @@ openpty (int *amaster, int *aslave, char *name,
   char _buf[512];
 #endif
   char *buf = _buf;
-  int master, slave;
+  int master, slave = -1;
 
   master = getpt ();
   if (master == -1)
@@ -135,6 +135,8 @@ openpty (int *amaster, int *aslave, char *name,
 
  fail:
   close (master);
+  if (slave != -1)
+    close(slave);
   return -1;
 }
 libutil_hidden_def (openpty)
-- 
2.14.1


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