From b197d6318e2da197ce026c7df961a0453a932b2e Mon Sep 17 00:00:00 2001 From: Ruben van Staden Date: Thu, 5 Sep 2024 08:16:55 -0400 Subject: [PATCH] fix leaking slice capacity --- .../internal/modeldecoder/modeldecoderutil/slice.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/input/elasticapm/internal/modeldecoder/modeldecoderutil/slice.go b/input/elasticapm/internal/modeldecoder/modeldecoderutil/slice.go index 53a4f429..2eaa5f8f 100644 --- a/input/elasticapm/internal/modeldecoder/modeldecoderutil/slice.go +++ b/input/elasticapm/internal/modeldecoder/modeldecoderutil/slice.go @@ -27,7 +27,9 @@ func Reslice[Slice ~[]model, model any](slice Slice, n int) Slice { if n > cap(slice) { slice = slices.Grow(slice, n-len(slice)) } - return slice[:n] + res := make(Slice, n) + copy(res, slice[:n]) + return res } // ResliceAndPopulateNil ensures a slice of pointers has atleast