]> granicus.if.org Git - procps-ng/commitdiff
top: replaced one use of fputs(3) with a write(2) call
authorShaohua Zhan <shaohua.zhan@windriver.com>
Sun, 21 Mar 2021 16:00:00 +0000 (00:00 +0800)
committerCraig Small <csmall@dropbear.xyz>
Tue, 23 Mar 2021 10:43:13 +0000 (21:43 +1100)
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>
top/top.c

index f4f82be487f3729b612b66e637213e600df448c2..951c240cf8aac7a085dfb874dae5c84a7aa7a8a1 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -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