summaryrefslogtreecommitdiff
path: root/lib/closeout.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-05-19 08:52:38 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2017-05-19 08:56:01 -0700
commit105ff45093137b71507172d426837414ce1b7668 (patch)
tree95bd631289a4ddf97709ab4941679da390b545c0 /lib/closeout.c
parentfa529e849b9e8e0083d84aa60c9023195a94a11f (diff)
downloadgnulib-105ff45093137b71507172d426837414ce1b7668.tar.gz
closeout: don’t close stderr when sanitizing
* NEWS: Document this. * lib/closeout.c (__has_feature): New macro, if not already defined. (SANITIZE_ADDRESS): New constant. (close_stdout): Don’t close stderr if sanitizing addresses.
Diffstat (limited to 'lib/closeout.c')
-rw-r--r--lib/closeout.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/closeout.c b/lib/closeout.c
index a23388f9c7..2a3f79152d 100644
--- a/lib/closeout.c
+++ b/lib/closeout.c
@@ -33,6 +33,16 @@
#include "exitfail.h"
#include "quotearg.h"
+#ifndef __has_feature
+# define __has_feature(a) false
+#endif
+
+#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)
+enum { SANITIZE_ADDRESS = true };
+#else
+enum { SANITIZE_ADDRESS = false };
+#endif
+
static const char *file_name;
/* Set the file name to be reported in the event an error is detected
@@ -119,6 +129,8 @@ close_stdout (void)
_exit (exit_failure);
}
- if (close_stream (stderr) != 0)
- _exit (exit_failure);
+ /* Close stderr only if not sanitizing, as sanitizers may report to
+ stderr after this function returns. */
+ if (!SANITIZE_ADDRESS && close_stream (stderr) != 0)
+ _exit (exit_failure);
}