top: replaced one use of fputs(3) with a write(2) call

This patch is ported from a merge request shown below,
and the following represents the original commit text.

------------------------------------------------------
top: In the bye_bye function, replace fputs with the write interface.

When top calls malloc, if a signal is received, it will
call sig_endpgm to process the signal. In the bye_bye function, if the
-b option is enable, the Batch variable is set, the fputs function
will calls malloc at the same time. The malloc function is not reentrant, so
it will cause the program to crash.

Signed-off-by: Shaohua Zhan <shaohua.zhan@windriver.com>
------------------------------------------------------

Reference(s):
https://gitlab.com/procps-ng/procps/-/merge_requests/127

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Shaohua Zhan 2021-03-22 00:00:00 +08:00 committed by Craig Small
parent 2e1e8fcc85
commit 6b8980a3b6

View File

@ -417,7 +417,9 @@ static void bye_bye (const char *str) {
fputs(str, stderr);
exit(EXIT_FAILURE);
}
if (Batch) fputs("\n", stdout);
if (Batch) {
write(fileno(stdout), "\n", sizeof("\n"));
}
exit(EXIT_SUCCESS);
} // end: bye_bye