From a80c8043d0010092795d952c77d3ec0f28d2c70e Mon Sep 17 00:00:00 2001 From: MinarKotonoha Date: Mon, 8 Apr 2024 16:39:00 +0800 Subject: [PATCH] common-main.c: fflush stdout buffer when exit By default, the buffer type of Windows' stdout is no buffer (_IONBF), and there is no need to manually fflush stdout. But some program, such as Windows Filtering Platform driver provided by the security software, may change the buffer type of stdout to Full buffering. Therefore, fflush(stdout) needs to be called manually, otherwise there will be no output to stdout. According to common sense, when the program exits, the stdout buffer should be automatically output and released, but not on Windows. So this commit will do it. Signed-off-by: MinarKotonoha --- common-main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/common-main.c b/common-main.c index 033778b3c56a35..73db581965a203 100644 --- a/common-main.c +++ b/common-main.c @@ -75,6 +75,13 @@ static void check_bug_if_BUG(void) /* We wrap exit() to call common_exit() in git-compat-util.h */ int common_exit(const char *file, int line, int code) { + /* + * Windows Filtering Platform driver provided by the security software + * may change buffer type of stdout from _IONBF to _IOFBF. + * It will no output without fflush manually. + */ + fflush(stdout); + /* * For non-POSIX systems: Take the lowest 8 bits of the "code" * to e.g. turn -1 into 255. On a POSIX system this is