Merge pull request #29628 from mehrdadbn9/fix/29627-stats-nil-pointer

fix(api): nil check Memory.Limit before dereference in stats handler
This commit is contained in:
Miloslav Trmač 2026-08-24 15:43:09 +02:00 committed by GitHub
commit ca42cbff0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -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)
}

View file

@ -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