include/closestream: avoid close more than once

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2019-06-13 13:25:44 +02:00
parent 25b7045e5d
commit 52aa1a6611
1 changed files with 5 additions and 2 deletions

View File

@ -39,7 +39,7 @@ close_stream(FILE * stream)
static inline void static inline void
close_stdout(void) close_stdout(void)
{ {
if (close_stream(stdout) != 0 && !(errno == EPIPE)) { if (stdout && close_stream(stdout) != 0 && !(errno == EPIPE)) {
if (errno) if (errno)
warn(_("write error")); warn(_("write error"));
else else
@ -47,8 +47,11 @@ close_stdout(void)
_exit(CLOSE_EXIT_CODE); _exit(CLOSE_EXIT_CODE);
} }
if (close_stream(stderr) != 0) if (stderr && close_stream(stderr) != 0)
_exit(CLOSE_EXIT_CODE); _exit(CLOSE_EXIT_CODE);
stdout = NULL;
stderr = NULL;
} }
static inline void static inline void