From a9e6a71f9435a50c582993e946be4d53828bb48d Mon Sep 17 00:00:00 2001
From: maminjie <maminjie1@huawei.com>
Date: Sat, 13 Mar 2021 16:03:03 +0800
Subject: [PATCH] Fix the invalid memory address or nil pointer reference

---
 libpod/stats.go | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libpod/stats.go b/libpod/stats.go
index c58a461..97a2169 100644
--- a/libpod/stats.go
+++ b/libpod/stats.go
@@ -57,9 +57,11 @@ func (c *Container) GetContainerStats(previousStats *ContainerStats) (*Container
 	previousCPU := previousStats.CPUNano
 	previousSystem := previousStats.SystemNano
 	stats.CPU = calculateCPUPercent(cgroupStats, previousCPU, previousSystem)
-	stats.MemUsage = cgroupStats.Memory.Usage.Usage
-	stats.MemLimit = getMemLimit(cgroupStats.Memory.Usage.Limit)
-	stats.MemPerc = (float64(stats.MemUsage) / float64(stats.MemLimit)) * 100
+    if cgroupStats.Memory != nil {
+	    stats.MemUsage = cgroupStats.Memory.Usage.Usage
+	    stats.MemLimit = getMemLimit(cgroupStats.Memory.Usage.Limit)
+	    stats.MemPerc = (float64(stats.MemUsage) / float64(stats.MemLimit)) * 100
+    }
 	stats.PIDs = 0
 	if conState == ContainerStateRunning {
 		stats.PIDs = cgroupStats.Pids.Current
-- 
2.23.0

