From 7e8fba78890a6a52dc45dd49ec9f42480484b763 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Thu, 28 Dec 2017 05:33:59 +0000 Subject: [PATCH] Close slave on fork error to prevent pty fd leak. CID: 978209 --- lib/libutil/pty.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/libutil/pty.c b/lib/libutil/pty.c index 1ef445a7b3b..8faf9154538 100644 --- a/lib/libutil/pty.c +++ b/lib/libutil/pty.c @@ -101,12 +101,13 @@ forkpty(int *amaster, char *name, struct termios *termp, struct winsize *winp) return (-1); switch (pid = fork()) { case -1: + (void)close(slave); return (-1); case 0: /* * child */ - (void) close(master); + (void)close(master); login_tty(slave); return (0); }