mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-24 23:15:46 +00:00
Linux: allocate cpuData before reading cpu count.
This commit is contained in:
parent
3f0c172a60
commit
ba4c67942c
@ -174,16 +174,19 @@ static void LinuxProcessList_updateCPUcount(ProcessList* super) {
|
||||
LinuxProcessList* this = (LinuxProcessList*) super;
|
||||
unsigned int existing = 0, active = 0;
|
||||
|
||||
DIR* dir = opendir("/sys/devices/system/cpu");
|
||||
if (!dir) {
|
||||
// Initialize the cpuData array before anything else.
|
||||
if (!this->cpuData) {
|
||||
this->cpuData = xReallocArrayZero(this->cpuData, super->existingCPUs ? (super->existingCPUs + 1) : 0, 2, sizeof(CPUData));
|
||||
this->cpuData[0].online = true; /* average is always "online" */
|
||||
this->cpuData[1].online = true;
|
||||
super->activeCPUs = 1;
|
||||
super->existingCPUs = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
DIR* dir = opendir("/sys/devices/system/cpu");
|
||||
if (!dir)
|
||||
return;
|
||||
|
||||
unsigned int currExisting = super->existingCPUs;
|
||||
|
||||
const struct dirent* entry;
|
||||
@ -233,6 +236,10 @@ static void LinuxProcessList_updateCPUcount(ProcessList* super) {
|
||||
|
||||
closedir(dir);
|
||||
|
||||
// return if no CPU is found
|
||||
if (existing < 1)
|
||||
return;
|
||||
|
||||
#ifdef HAVE_SENSORS_SENSORS_H
|
||||
/* When started with offline CPUs, libsensors does not monitor those,
|
||||
* even when they become online. */
|
||||
|
Loading…
Reference in New Issue
Block a user