From 631f4d3ae6adfda84d1a110781d9402c12e16cfc Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Sat, 28 May 2011 16:43:26 +0300 Subject: [PATCH] Don't call close(-1) in tuklib_open_stdxxx() on error. Thanks to Jim Meyering. --- src/common/tuklib_open_stdxxx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common/tuklib_open_stdxxx.c b/src/common/tuklib_open_stdxxx.c index 08bc60d8..26702a6a 100644 --- a/src/common/tuklib_open_stdxxx.c +++ b/src/common/tuklib_open_stdxxx.c @@ -39,12 +39,14 @@ tuklib_open_stdxxx(int err_status) | (i == 0 ? O_WRONLY : O_RDONLY)); if (fd != i) { + if (fd != -1) + (void)close(fd); + // Something went wrong. Exit with the // exit status we were given. Don't try // to print an error message, since stderr // may very well be non-existent. This // error should be extremely rare. - (void)close(fd); exit(err_status); } }