Skip to content

Commit

Permalink
Don't use bytes.NewBuffer to read data
Browse files Browse the repository at this point in the history
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č <[email protected]>
  • Loading branch information
mtrmac committed Apr 14, 2023
1 parent 6c32bf1 commit e9356ba
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion libpod/oci_conmon_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/infra/abi/play_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e9356ba

Please sign in to comment.