summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2022-04-02 12:38:00 +0200
committerDaniel Lange <DLange@git.local>2022-04-02 12:38:00 +0200
commit8b927ba5967fd1a866a98d2fdb8b027630f658ea (patch)
tree09e96a14cf96e2f34cad9524d86a31c154d4602a
parent0ffd772d28bdf2fb1f0ef5abbb6fff17223edee9 (diff)
parent64fb7181ee4fa4d0f2a22d202d33971899b53f08 (diff)
Merge branch 'main' (Linux: fix crash in LXD, fixes #965) of er-azh/htop into main
-rw-r--r--linux/LinuxProcessList.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index b0e6f03a..f365ff21 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -174,21 +174,24 @@ 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) {
- this->cpuData = xReallocArrayZero(this->cpuData, super->existingCPUs ? (super->existingCPUs + 1) : 0, 2, sizeof(CPUData));
+ // Initialize the cpuData array before anything else.
+ if (!this->cpuData) {
+ this->cpuData = xCalloc(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;
while ((entry = readdir(dir)) != NULL) {
- if (entry->d_type != DT_DIR)
+ if (entry->d_type != DT_DIR && entry->d_type != DT_UNKNOWN)
continue;
if (!String_startsWith(entry->d_name, "cpu"))
@@ -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. */

© 2014-2024 Faster IT GmbH | imprint | privacy policy