From 0c63c42f8183d13c2c106c01f5bb3560d39b3295 Mon Sep 17 00:00:00 2001 From: bin liu Date: Sat, 12 Nov 2022 00:09:31 +0800 Subject: [PATCH] Fix slice append error In golang when copy a slice, if the slice is initialized with a desired length, then appending to it will cause the size double. Signed-off-by: bin liu --- pkg/cri/server/helpers.go | 2 +- pkg/cri/store/container/status.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cri/server/helpers.go b/pkg/cri/server/helpers.go index 06d7b588e..92efa03e4 100644 --- a/pkg/cri/server/helpers.go +++ b/pkg/cri/server/helpers.go @@ -474,7 +474,7 @@ func copyResourcesToStatus(spec *runtimespec.Spec, status containerstore.Status) } if spec.Linux.Resources.HugepageLimits != nil { - hugepageLimits := make([]*runtime.HugepageLimit, len(spec.Linux.Resources.HugepageLimits)) + hugepageLimits := make([]*runtime.HugepageLimit, 0) for _, l := range spec.Linux.Resources.HugepageLimits { hugepageLimits = append(hugepageLimits, &runtime.HugepageLimit{ PageSize: l.Pagesize, diff --git a/pkg/cri/store/container/status.go b/pkg/cri/store/container/status.go index b50dc5c54..e12fb0f44 100644 --- a/pkg/cri/store/container/status.go +++ b/pkg/cri/store/container/status.go @@ -219,7 +219,7 @@ func deepCopyOf(s Status) Status { } copy.Resources = &runtime.ContainerResources{} if s.Resources != nil && s.Resources.Linux != nil { - hugepageLimits := make([]*runtime.HugepageLimit, len(s.Resources.Linux.HugepageLimits)) + hugepageLimits := make([]*runtime.HugepageLimit, 0) for _, l := range s.Resources.Linux.HugepageLimits { hugepageLimits = append(hugepageLimits, &runtime.HugepageLimit{ PageSize: l.PageSize,