[1/2] openpty: close slave pty fd on error
Commit Message
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(-)
Comments
On 08/26/2017 03:44 PM, Christian Brauner wrote:
> fail:
> close (master);
> + if (slave != -1)
> + close(slave);
> return -1;
This is inconsistent with how the code frees buf if there is an error:
For buf, the free operation happens before the fail tail. I think we
should keep this consistent: either free exactly what is needed, or have
a single function exit which checks for initialization and frees what
has been allocated.
Thanks,
Florian
@@ -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__]
@@ -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)