fix: json.Unmarshal not resetting struct fields (#345)

The json.Unmarshal function was not properly resetting the Stats struct fields between iterations in the loop. This caused incorrect values to be retained from previous iterations, leading to unexpected behavior.

This commit fixes the issue by zero the struct in each loop iteration, ensures that each unmarshaling operation starts with a clean struct, preventing value carryover.
This commit is contained in:
Chuangbo Li
2024-12-29 06:06:37 +08:00
committed by GitHub
parent 558d051c42
commit 19b4477a75

View File

@@ -155,6 +155,7 @@ func (rm *RecordManager) AverageSystemStats(records RecordStats) system.Stats {
var stats system.Stats
for i := range records {
stats = system.Stats{} // Zero the struct before unmarshalling
json.Unmarshal(records[i].Stats, &stats)
sum.Cpu += stats.Cpu
sum.Mem += stats.Mem