From d9d2ef991caabb3d2d0d419b652e7894cd2f4546 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sat, 24 Sep 2022 13:13:14 +0800 Subject: [PATCH] net/http: fix the potential leak of textproto.Reader from pool Fixes #55835 Change-Id: I6109bab2941b859e8cfef22f65a6a3a5f977a8d7 Reviewed-on: https://go-review.googlesource.com/c/go/+/433835 TryBot-Result: Gopher Robot Reviewed-by: Damien Neil Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Run-TryBot: Andy Pan Run-TryBot: Ian Lance Taylor --- src/net/http/request.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/net/http/request.go b/src/net/http/request.go index 924ca1b390..88d3d75af5 100644 --- a/src/net/http/request.go +++ b/src/net/http/request.go @@ -1030,6 +1030,8 @@ func ReadRequest(b *bufio.Reader) (*Request, error) { func readRequest(b *bufio.Reader) (req *Request, err error) { tp := newTextprotoReader(b) + defer putTextprotoReader(tp) + req = new(Request) // First line: GET /index.html HTTP/1.0 @@ -1038,7 +1040,6 @@ func readRequest(b *bufio.Reader) (req *Request, err error) { return nil, err } defer func() { - putTextprotoReader(tp) if err == io.EOF { err = io.ErrUnexpectedEOF }