__cxa_finalize: skip fflush call on dlclose

In __cxa_finalize, only call fflush(NULL) when the program is exiting, not
when a library is unloaded with dlclose. This change restores behavior
from 2015.

Flushing output is needed when the program exits, but flushing everything
is hazardous at other times because it can block -- fflush(NULL) locks
every file, so it also blocks on read operations.

Bug: http://b/130655235
Test: manual
Change-Id: I2f5ecffa6724bfd98a93d145ab5313c793c01ae6
diff --git a/libc/stdlib/atexit.c b/libc/stdlib/atexit.c
index bd6ac3d..692e0c0 100644
--- a/libc/stdlib/atexit.c
+++ b/libc/stdlib/atexit.c
@@ -186,7 +186,10 @@
 	}
 	_ATEXIT_UNLOCK();
 
-  fflush(NULL);
+	/* If called via exit(), flush output of all open files. */
+	if (dso == NULL) {
+		fflush(NULL);
+	}
 
   /* BEGIN android-changed: call __unregister_atfork if dso is not null */
   if (dso != NULL) {