From e9356ba206a399a4ec614a7959a1bd561b6151d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Fri, 14 Apr 2023 22:40:47 +0200 Subject: [PATCH] Don't use bytes.NewBuffer to read data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The documentation says > The new Buffer takes ownership of buf, and the > caller should not use buf after this call. so use the more directly applicable, and simpler, bytes.Reader instead, to avoid this potentially risky use. Signed-off-by: Miloslav Trmač --- libpod/oci_conmon_common.go | 2 +- pkg/domain/infra/abi/play_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libpod/oci_conmon_common.go b/libpod/oci_conmon_common.go index 6dd54a8bc6..d803276b15 100644 --- a/libpod/oci_conmon_common.go +++ b/libpod/oci_conmon_common.go @@ -257,7 +257,7 @@ func (r *ConmonOCIRuntime) UpdateContainerStatus(ctr *Container) error { if err != nil { return fmt.Errorf("reading stdout: %s: %w", ctr.ID(), err) } - if err := json.NewDecoder(bytes.NewBuffer(out)).Decode(state); err != nil { + if err := json.NewDecoder(bytes.NewReader(out)).Decode(state); err != nil { return fmt.Errorf("decoding container status for container %s: %w", ctr.ID(), err) } ctr.state.PID = state.Pid diff --git a/pkg/domain/infra/abi/play_test.go b/pkg/domain/infra/abi/play_test.go index bdc81ada85..88d5696c11 100644 --- a/pkg/domain/infra/abi/play_test.go +++ b/pkg/domain/infra/abi/play_test.go @@ -99,7 +99,7 @@ binaryData: for _, test := range tests { test := test t.Run(test.name, func(t *testing.T) { - buf := bytes.NewBufferString(test.configMapContent) + buf := bytes.NewReader([]byte(test.configMapContent)) cm, err := readConfigMapFromFile(buf) if test.expectError {