From cc3a4e2f9e0cba571499b3e1e49cd9b13b30f09b Mon Sep 17 00:00:00 2001 From: Petter Reinholdtsen Date: Fri, 7 Feb 2014 09:50:14 +0000 Subject: [PATCH] Avoid reusing open file descriptor to make it easier to pinpoint Coverity CID 1164479 resource leak. --- src/init.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/init.c b/src/init.c index 4187553..2569a54 100644 --- a/src/init.c +++ b/src/init.c @@ -1170,15 +1170,16 @@ pid_t spawn(CHILD *ch, int *res) /* Set ioctl settings to default ones */ console_stty(); - } else { + } else { /* parent */ + int fd; setsid(); - if ((f = console_open(O_RDWR|O_NOCTTY)) < 0) { + if ((fd = console_open(O_RDWR|O_NOCTTY)) < 0) { initlog(L_VB, "open(%s): %s", console_dev, strerror(errno)); - f = open("/dev/null", O_RDWR); + fd = open("/dev/null", O_RDWR); } - dup(f); - dup(f); + dup(fd); + dup(fd); } /*