Page MenuHomeFreeBSD

systat: Avoid incorrect reallocation in pigs.c

Authored by on Mar 17 2021, 12:42 AM.



Let's say nproc comes back in 3, 1, 2, the reallocation happens on the 3rd
fetch given lastnproc 1 is smaller than nproc 2. However, we reserved 3 slots
and thus don't need to reallocate.

Stop free() even if kvm_getprocs as we can come back but set nprocs = 0.
Check nprocs in showpigs() to ensure not try displaying with kvm_getprocs failed.
Current code can have pt with non-null after kvm_getprocs() failure.

Replace to realloc for simpler operations.

Test Plan

% systat -pigs

Diff Detail

R10 FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.