public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] openpty: close slave pty fd on error
@ 2017-08-26 14:21 Christian Brauner
  2017-08-26 14:21 ` [PATCH 2/2] openpty: use TIOCGPTPEER to open slave side fd Christian Brauner
  2017-08-29  9:07 ` [PATCH 1/2] openpty: close slave pty fd on error Florian Weimer
  0 siblings, 2 replies; 18+ messages in thread
From: Christian Brauner @ 2017-08-26 14:21 UTC (permalink / raw)
  To: libc-alpha, stgraber, serge; +Cc: Christian Brauner

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

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

end of thread, other threads:[~2017-09-20 10:53 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-26 14:21 [PATCH 1/2] openpty: close slave pty fd on error Christian Brauner
2017-08-26 14:21 ` [PATCH 2/2] openpty: use TIOCGPTPEER to open slave side fd Christian Brauner
2017-08-28  7:34   ` Florian Weimer
2017-08-28 11:14     ` Christian Brauner
2017-08-28 11:39     ` Joseph Myers
2017-08-28 12:11     ` [PATCH 2/2 v2] " Christian Brauner
2017-08-28 12:22       ` Joseph Myers
2017-08-28 12:34       ` Andreas Schwab
2017-08-28 12:51         ` [PATCH 2/2 v3] " Christian Brauner
2017-08-29  9:07 ` [PATCH 1/2] openpty: close slave pty fd on error Florian Weimer
2017-08-29 13:46   ` [PATCH 1/2 v4] " Christian Brauner
2017-08-29 13:46     ` [PATCH 2/2 v4] openpty: use TIOCGPTPEER to open slave side fd Christian Brauner
2017-08-29 14:00     ` [PATCH 1/2 v4] openpty: close slave pty fd on error Andreas Schwab
2017-08-29 14:12       ` Christian Brauner
2017-08-29 14:31       ` [PATCH 1/2 v5] " Christian Brauner
2017-08-29 14:31         ` [PATCH 2/2 v5] openpty: use TIOCGPTPEER to open slave side fd Christian Brauner
2017-09-10 17:45         ` [PATCH 1/2 v5] openpty: close slave pty fd on error Christian Brauner
2017-09-20 10:53           ` Christian Brauner

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