]> granicus.if.org Git - procps-ng/commitdiff
top: tweak end-of-job processing if invoked via signal
authorJim Warner <james.warner@comcast.net>
Thu, 16 Sep 2021 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@dropbear.xyz>
Mon, 20 Sep 2021 10:05:44 +0000 (20:05 +1000)
The master branch top is pretty well insulated against
signal-unsafe function calls during end-of-job action.

However, this newlib branch top had exposed himself to
a bunch of such unsafe activity in the form of 'unref'
function calls to the new library. In those guys there
will be several 'free' invocations which are not safe.

So, this commit will simply correct such an oversight.

Signed-off-by: Jim Warner <james.warner@comcast.net>
top/top.c

index 0e3614a03338de992db7fbb7e515b01a51531c61..c1e3aee02dd8e436bea4e79cb50ed1473f31fed3 100644 (file)
--- a/top/top.c
+++ b/top/top.c
@@ -417,9 +417,12 @@ static void bye_bye (const char *str) {
 }
 #endif // end: ATEOJ_RPTSTD
 
-   procps_meminfo_unref(&Mem_ctx);
-   procps_pids_unref(&Pids_ctx);
-   procps_stat_unref(&Stat_ctx);
+   // there's lots of signal-unsafe stuff in the following ...
+   if (Frames_signal != BREAK_sig) {
+      procps_pids_unref(&Pids_ctx);
+      procps_stat_unref(&Stat_ctx);
+      procps_meminfo_unref(&Mem_ctx);
+   }
 
    /* we'll only have a 'str' if called by error_exit() |
       not ever from the sig_endpgm() signal handler ... | */
@@ -444,6 +447,7 @@ static void error_exit (const char *str) __attribute__((__noreturn__));
 static void error_exit (const char *str) {
    static char buf[MEDBUFSIZ];
 
+   Frames_signal = BREAK_off;
    /* we'll use our own buffer so callers can still use fmtmk() and, after
       twelve long years, 2013 was the year we finally eliminated the leading
       tab character -- now our message can get lost in screen clutter too! */