]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include/closestream: avoid close more than once
authorKarel Zak <kzak@redhat.com>
Thu, 13 Jun 2019 11:25:44 +0000 (13:25 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 17 Jun 2019 13:46:10 +0000 (15:46 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/closestream.h

index 6a62e48e8a13522aaf9f8a60ad8acbca77afbce8..83df1ee7d9673ac13f7f300726e7ec440d20e1e2 100644 (file)
@@ -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