Skip to content

Commit

Permalink
Add defer putLengthReader to prevent leak
Browse files Browse the repository at this point in the history
Signed-off-by: Harish Shan <140232061+perhapsmaple@users.noreply.github.com>
  • Loading branch information
perhapsmaple committed Oct 2, 2023
1 parent 3edc716 commit 2c9d8eb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion modules/caddyhttp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var bodyReader *lengthReader
if r.Body != nil {
bodyReader = getLengthReader(r.Body)
defer putLengthReader(bodyReader)
r.Body = bodyReader
}

Expand Down Expand Up @@ -728,7 +729,6 @@ func (s *Server) logRequest(
reqBodyLength := 0
if bodyReader != nil {
reqBodyLength = bodyReader.Length
putLengthReader(bodyReader)
}

extra := r.Context().Value(ExtraLogFieldsCtxKey).(*ExtraLogFields)
Expand Down

0 comments on commit 2c9d8eb

Please sign in to comment.