From 52aa1a661110e235a9eff57bb4db88aa8412dac1 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 13 Jun 2019 13:25:44 +0200 Subject: include/closestream: avoid close more than once Signed-off-by: Karel Zak --- include/closestream.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/closestream.h b/include/closestream.h index 6a62e48e8..83df1ee7d 100644 --- a/include/closestream.h +++ b/include/closestream.h @@ -39,7 +39,7 @@ close_stream(FILE * stream) static inline void close_stdout(void) { - if (close_stream(stdout) != 0 && !(errno == EPIPE)) { + if (stdout && close_stream(stdout) != 0 && !(errno == EPIPE)) { if (errno) warn(_("write error")); else @@ -47,8 +47,11 @@ close_stdout(void) _exit(CLOSE_EXIT_CODE); } - if (close_stream(stderr) != 0) + if (stderr && close_stream(stderr) != 0) _exit(CLOSE_EXIT_CODE); + + stdout = NULL; + stderr = NULL; } static inline void -- cgit v1.2.3-55-g7522