From 9700db036cd49ef981bd82386ff0f58000ecfa05 Mon Sep 17 00:00:00 2001 From: Nelson Ferreira Date: Wed, 29 Feb 2012 16:07:06 -0500 Subject: [PATCH] Coverity: Resource leak: CID 400022 * src/emacs.c (main_1): Make sure the temporary descriptor is 0, which makes the "leak" intentional. Signed-off-by: Nelson Ferreira --- src/emacs.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/emacs.c b/src/emacs.c index d1d1b78..0965dbf 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1039,15 +1039,20 @@ DOESNT_RETURN main_1(int argc, char **argv, char **envp, int restart) char *term; if (argmatch (argv, argc, "-t", "--terminal", 4, &term, &skip_args)) { + int tdesc = -1; close(0); close(1); - if (open(term, O_RDWR | OPEN_BINARY, 2) < 0) + tdesc = open(term, O_RDWR | OPEN_BINARY, 2); + if (tdesc < 0) fatal("%s: %s", term, strerror(errno)); - if( dup(0) < 0) + assert(tdesc==0); + tdesc = dup(0); + if ( tdesc < 0) { fatal("dup failed %s: %s", term, strerror(errno)); - if (!isatty(0)) + } + if (!isatty(0)) { fatal("%s: not a tty", term); - + } #if 0 stderr_out("Using %s", ttyname(0)); #endif -- 2.34.1