diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2021-05-23 15:21:51 +0200 |
---|---|---|
committer | Christian Göttsche <cgzones@googlemail.com> | 2021-05-23 15:25:23 +0200 |
commit | 3d5b6d9282e584557999772d3cedd7e8ceddabbd (patch) | |
tree | 3695afaf34de58ed89dfa9baa1f302522a56f0fb /linux/LinuxProcessList.c | |
parent | 771a1be316d9aea91bec22c32288fe7b9d88d15c (diff) |
Fix assert failure on short running thread
The following assert failure might happen on short running threads with
an empty comm value in /proc/${pid}/stat:
htop: Process.c:1159: void Process_updateCmdline(Process *, const char *, int, int): Assertion `(cmdline && basenameStart < (int)strlen(cmdline)) || (!cmdline && basenameStart == 0)' failed.
The specific task is:
comm=''
exe='(null)'
cmdline='/usr/bin/ruby /usr/bin/how-can-i-help --apt'
So basenameStart is 0, while strlen(cmdline) is also 0.
Diffstat (limited to 'linux/LinuxProcessList.c')
-rw-r--r-- | linux/LinuxProcessList.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 6d3bbc84..e262ce7c 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1351,10 +1351,10 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_ } } - char command[MAX_NAME + 1]; + char statCommand[MAX_NAME + 1]; unsigned long long int lasttimes = (lp->utime + lp->stime); unsigned long int tty_nr = proc->tty_nr; - if (! LinuxProcessList_readStatFile(proc, procFd, command, sizeof(command))) + if (! LinuxProcessList_readStatFile(proc, procFd, statCommand, sizeof(statCommand))) goto errorReadingProcess; if (tty_nr != proc->tty_nr && this->ttyDrivers) { @@ -1431,11 +1431,11 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, openat_arg_ LinuxProcessList_readCwd(lp, procFd); } - if (proc->state == 'Z' && !proc->cmdline) { - Process_updateCmdline(proc, command, 0, 0); + if (proc->state == 'Z' && !proc->cmdline && statCommand[0]) { + Process_updateCmdline(proc, statCommand, 0, strlen(statCommand)); } else if (Process_isThread(proc)) { - if (settings->showThreadNames || Process_isKernelThread(proc)) { - Process_updateCmdline(proc, command, 0, 0); + if ((settings->showThreadNames || Process_isKernelThread(proc)) && statCommand[0]) { + Process_updateCmdline(proc, statCommand, 0, strlen(statCommand)); } if (Process_isKernelThread(proc)) { |