]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include/closestream: add close_stdout_atexit()
authorKarel Zak <kzak@redhat.com>
Tue, 16 Apr 2019 11:42:34 +0000 (13:42 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 16 Apr 2019 11:42:34 +0000 (13:42 +0200)
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 <kzak@redhat.com>
configure.ac
include/closestream.h

index cb72f42bdae5524ea8bb4afceacdd2f89a3b19e8..d2c8f92fe6c17b85e2c6e4bf89e36ee06f3a6180 100644 (file)
@@ -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])
index b3b257c94abee8f0f0f10649ecc46b7484bd17b3..0ce34fe52dc287948a5e2883a8b7590faee23be1 100644 (file)
@@ -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__)))