mirror of https://github.com/xzeldon/htop.git
Linux: zero CPU data after allocation
Zero all the CPU data, like totalPeriod, after its memory allocation via realloc(3). Conditional jump or move depends on uninitialised value(s) at 0x132A9B: LinuxProcessList_scanCPUTime (LinuxProcessList.c:1928) by 0x1358C3: ProcessList_goThroughEntries (LinuxProcessList.c:2079) by 0x12A79A: ProcessList_scan (ProcessList.c:627) by 0x11CA67: CommandLine_run (CommandLine.c:357) by 0x4A81E49: (below main) (libc-start.c:314) Uninitialised value was created by a heap allocation at 0x48396C5: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x12F633: xRealloc (XUtils.c:64) by 0x12F633: xReallocArray (XUtils.c:78) by 0x1325A8: LinuxProcessList_updateCPUcount (LinuxProcessList.c:207) by 0x134E0A: ProcessList_new (LinuxProcessList.c:284) by 0x11C8D0: CommandLine_run (CommandLine.c:301) by 0x4A81E49: (below main) (libc-start.c:314)
This commit is contained in:
parent
bf395e10c5
commit
43ffdb0eda
|
@ -167,11 +167,11 @@ static void LinuxProcessList_updateCPUcount(ProcessList* super) {
|
||||||
|
|
||||||
DIR* dir = opendir("/sys/devices/system/cpu");
|
DIR* dir = opendir("/sys/devices/system/cpu");
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
super->activeCPUs = 1;
|
this->cpuData = xReallocArrayZero(this->cpuData, super->existingCPUs ? (super->existingCPUs + 1) : 0, 2, sizeof(CPUData));
|
||||||
super->existingCPUs = 1;
|
|
||||||
this->cpuData = xReallocArray(this->cpuData, 2, sizeof(CPUData));
|
|
||||||
this->cpuData[0].online = true; /* average is always "online" */
|
this->cpuData[0].online = true; /* average is always "online" */
|
||||||
this->cpuData[1].online = true;
|
this->cpuData[1].online = true;
|
||||||
|
super->activeCPUs = 1;
|
||||||
|
super->existingCPUs = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,10 +204,7 @@ static void LinuxProcessList_updateCPUcount(ProcessList* super) {
|
||||||
/* readdir() iterates with no specific order */
|
/* readdir() iterates with no specific order */
|
||||||
unsigned int max = MAXIMUM(existing, id + 1);
|
unsigned int max = MAXIMUM(existing, id + 1);
|
||||||
if (max > currExisting) {
|
if (max > currExisting) {
|
||||||
this->cpuData = xReallocArray(this->cpuData, max + /* aggregate */ 1, sizeof(CPUData));
|
this->cpuData = xReallocArrayZero(this->cpuData, currExisting ? (currExisting + 1) : 0, max + /* aggregate */ 1, sizeof(CPUData));
|
||||||
for (unsigned int j = currExisting; j < max; j++) {
|
|
||||||
this->cpuData[j].online = false;
|
|
||||||
}
|
|
||||||
this->cpuData[0].online = true; /* average is always "online" */
|
this->cpuData[0].online = true; /* average is always "online" */
|
||||||
currExisting = max;
|
currExisting = max;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue