diff --git a/pkg/api/handlers/compat/containers_stats_linux.go b/pkg/api/handlers/compat/containers_stats_linux.go index e6309f9b18..cce67d20b5 100644 --- a/pkg/api/handlers/compat/containers_stats_linux.go +++ b/pkg/api/handlers/compat/containers_stats_linux.go @@ -72,7 +72,7 @@ func statsContainerJSON(ctnr *libpod.Container, stats *define.ContainerStats, pr resources := ctnr.LinuxResources() memoryLimit := cgroupStat.MemoryStats.Usage.Limit - if resources != nil && resources.Memory != nil && *resources.Memory.Limit > 0 { + if resources != nil && resources.Memory != nil && resources.Memory.Limit != nil && *resources.Memory.Limit > 0 { memoryLimit = uint64(*resources.Memory.Limit) } diff --git a/test/apiv2/19-stats.at b/test/apiv2/19-stats.at index 2ca4b02daf..4431ab8fbb 100644 --- a/test/apiv2/19-stats.at +++ b/test/apiv2/19-stats.at @@ -27,3 +27,9 @@ podman rm -f testctr2 podman network rm testnet1 podman network rm testnet2 + +# regression for https://github.com/containers/podman/issues/29627 +# stats should not panic when memory-reservation is set without memory-limit +podman run -dt --name testctr3 --memory-reservation=10m $IMAGE top &>/dev/null +t GET libpod/containers/testctr3/stats?stream=false 200 +podman rm -f testctr3