diff options
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | include/closestream.h | 11 |
2 files changed, 13 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index cb72f42bd..d2c8f92fe 100644 --- a/configure.ac +++ b/configure.ac @@ -156,6 +156,8 @@ AC_ARG_ENABLE([asan], AS_IF([test "x$enable_asan" = xyes], [ UL_WARN_ADD([-fsanitize=address]) ASAN_LDFLAGS="-fsanitize=address" +],[ + AC_DEFINE([USE_CLOSE_ATEXIT], [1], [close stdout at exit]) ]) AC_SUBST([ASAN_LDFLAGS]) diff --git a/include/closestream.h b/include/closestream.h index b3b257c94..0ce34fe52 100644 --- a/include/closestream.h +++ b/include/closestream.h @@ -51,6 +51,17 @@ close_stdout(void) _exit(CLOSE_EXIT_CODE); } +static inline void +close_stdout_atexit(void) +{ + /* + * Note that close stdout at exit disables ASAN to report memory leaks + */ +#ifdef USE_CLOSE_ATEXIT + atexit(close_stdout); +#endif +} + #ifndef HAVE_FSYNC static inline int fsync(int fd __attribute__((__unused__))) |