top: harden management of 'Hide_pid' array allocations
While setting the size of that Hide_pid array to equal total pids high water mark was probably safe, in truth there is no real relationship. At some point one could exceed that HWM if the 'v' toggle was used extensively and at least 1 of those entries remained non-negative. This commit simply divorces Hide_tot from the pids HWM and bases Hide_pid array size on actual run-time need. Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
22ae537707
commit
ca9142767c
19
top/top.c
19
top/top.c
@ -4331,7 +4331,6 @@ static void forest_begin (WIN_t *q) {
|
|||||||
if (hwmsav < PIDSmaxt) { // grow, but never shrink
|
if (hwmsav < PIDSmaxt) { // grow, but never shrink
|
||||||
hwmsav = PIDSmaxt;
|
hwmsav = PIDSmaxt;
|
||||||
Tree_ppt = alloc_r(Tree_ppt, sizeof(void *) * hwmsav);
|
Tree_ppt = alloc_r(Tree_ppt, sizeof(void *) * hwmsav);
|
||||||
Hide_pid = alloc_r(Hide_pid, sizeof(int) * hwmsav);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TREE_SCANALL
|
#ifndef TREE_SCANALL
|
||||||
@ -4986,11 +4985,19 @@ static void keys_task (int ch) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i == Hide_tot) Hide_pid[Hide_tot++] = pid;
|
if (i == Hide_tot) {
|
||||||
// plenty of room, but if everything's expanded let's reset ...
|
static int totsav;
|
||||||
for (i = 0; i < Hide_tot; i++)
|
if (Hide_tot >= totsav) {
|
||||||
if (Hide_pid[i] > 0) break;
|
totsav += 128;
|
||||||
if (i == Hide_tot) Hide_tot = 0;
|
Hide_pid = alloc_r(Hide_pid, sizeof(int) * totsav);
|
||||||
|
}
|
||||||
|
Hide_pid[Hide_tot++] = pid;
|
||||||
|
} else {
|
||||||
|
// if everything's expanded, let's empty the array ...
|
||||||
|
for (i = 0; i < Hide_tot; i++)
|
||||||
|
if (Hide_pid[i] > 0) break;
|
||||||
|
if (i == Hide_tot) Hide_tot = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user