From: Karel Zak Date: Tue, 16 Apr 2019 11:42:34 +0000 (+0200) Subject: include/closestream: add close_stdout_atexit() X-Git-Tag: v2.34-rc1~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31c66833cb8e3aad8af0eea4a1744e9e14f657b9;p=thirdparty%2Futil-linux.git include/closestream: add close_stdout_atexit() It seems better to have a way to control when atexit(close_stdout()) is used, because close stdout means that for example ASAN (or another into binary integrated tool) is not able to print the final summary. Signed-off-by: Karel Zak --- diff --git a/configure.ac b/configure.ac index cb72f42bda..d2c8f92fe6 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 b3b257c94a..0ce34fe52d 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__)))