Skip to content

Commit 7240fcf

Browse files
committed
routing/http: do not leak a bytes.Buffer in drjson
1 parent db4e43a commit 7240fcf

File tree

1 file changed

+4
-4
lines changed
  • routing/http/internal/drjson

1 file changed

+4
-4
lines changed

routing/http/internal/drjson/json.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ import (
55
"encoding/json"
66
)
77

8-
func marshalJSON(val any) (*bytes.Buffer, error) {
8+
func marshalJSON(val any) ([]byte, error) {
99
buf := &bytes.Buffer{}
1010
enc := json.NewEncoder(buf)
1111
enc.SetEscapeHTML(false)
1212
err := enc.Encode(val)
13-
return buf, err
13+
return buf.Bytes(), err
1414
}
1515

1616
// MarshalJSONBytes is needed to avoid changes
1717
// on the original bytes due to HTML escapes.
1818
func MarshalJSONBytes(val any) ([]byte, error) {
19-
buf, err := marshalJSON(val)
19+
bytes, err := marshalJSON(val)
2020
if err != nil {
2121
return nil, err
2222
}
2323

2424
// remove last \n added by Encode
25-
return buf.Bytes()[:buf.Len()-1], nil
25+
return bytes[:len(bytes)-1], nil
2626
}

0 commit comments

Comments
 (0)