Skip to content

Commit

Permalink
Fix some potential pool leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Nov 16, 2022
1 parent 8a60232 commit 8428321
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion client.go
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion http.go
Expand Up @@ -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()
Expand All @@ -1983,7 +1985,6 @@ func getHTTPString(hw httpWriter) string {
return err.Error()
}
s := string(w.B)
bytebufferpool.Put(w)
return s
}

Expand Down

0 comments on commit 8428321

Please sign in to comment.