From 7c4aead6e36fd3519b13aa84ec811c8aa07344e0 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sat, 19 Aug 2023 00:13:00 +0200 Subject: [PATCH] fix profileData initialisation --- internal/pgopher/collector.go | 2 +- internal/pgopher/http.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/pgopher/collector.go b/internal/pgopher/collector.go index e257416..6d52cf8 100644 --- a/internal/pgopher/collector.go +++ b/internal/pgopher/collector.go @@ -85,7 +85,7 @@ func (p profileCollector) Run() { case "kubernetes": name := fmt.Sprintf("pgopher-profile-%s", p.target.Name) - profileData := make([]byte, 0, buf.Len()) + profileData := make([]byte, base64.StdEncoding.EncodedLen(buf.Len())) base64.StdEncoding.Encode(profileData, buf.Bytes()) diff --git a/internal/pgopher/http.go b/internal/pgopher/http.go index 65bcf63..47a7b0e 100644 --- a/internal/pgopher/http.go +++ b/internal/pgopher/http.go @@ -84,7 +84,7 @@ func (s *Server) handleProfile(ctx echo.Context) error { defer file.Close() defer os.Remove(file.Name()) - profileData := make([]byte, 0, len(resp.Data["profile"])) + profileData := make([]byte, base64.StdEncoding.DecodedLen(len(resp.Data["profile"]))) _, err = base64.StdEncoding.Decode(profileData, resp.Data["profile"]) if err != nil {