From c367454ffe184d396c0fabc40e7b365e4c40231f Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Wed, 16 Nov 2022 12:46:28 +0800 Subject: [PATCH] Fix some potential pool leaks (#1433) --- client.go | 3 ++- http.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/client.go b/client.go index a2d9b50f0e..e4450919fe 100644 --- a/client.go +++ b/client.go @@ -983,6 +983,8 @@ var clientURLResponseChPool sync.Pool func clientPostURL(dst []byte, url string, postArgs *Args, c clientDoer) (statusCode int, body []byte, err error) { req := AcquireRequest() + defer ReleaseRequest(req) + req.Header.SetMethod(MethodPost) req.Header.SetContentTypeBytes(strPostArgsContentType) if postArgs != nil { @@ -993,7 +995,6 @@ func clientPostURL(dst []byte, url string, postArgs *Args, c clientDoer) (status statusCode, body, err = doRequestFollowRedirectsBuffer(req, dst, url, c) - ReleaseRequest(req) return statusCode, body, err } diff --git a/http.go b/http.go index 4b9e113a46..25defadd70 100644 --- a/http.go +++ b/http.go @@ -1975,6 +1975,8 @@ func (resp *Response) String() string { func getHTTPString(hw httpWriter) string { w := bytebufferpool.Get() + defer bytebufferpool.Put(w) + bw := bufio.NewWriter(w) if err := hw.Write(bw); err != nil { return err.Error() @@ -1983,7 +1985,6 @@ func getHTTPString(hw httpWriter) string { return err.Error() } s := string(w.B) - bytebufferpool.Put(w) return s }