From 03a7df4bf7e807cb04f22fb647a6bd5daeb386d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=96=AEdar=20=E4=BA=8E=C9=A6=CA=B7a?= <65339668+darhwa@users.noreply.github.com> Date: Sun, 21 Jun 2020 01:21:32 +0800 Subject: [PATCH] Fix misuse of sync.Pool (#76) --- forwardproxy.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/forwardproxy.go b/forwardproxy.go index 32235af..5fb26fb 100644 --- a/forwardproxy.go +++ b/forwardproxy.go @@ -579,6 +579,7 @@ func dualStream(target net.Conn, clientReader io.ReadCloser, clientWriter io.Wri buf := bufferPool.Get().([]byte) buf = buf[0:cap(buf)] _, _err := flushingIoCopy(w, r, buf) + bufferPool.Put(buf) if cw, ok := w.(closeWriter); ok { cw.CloseWrite() } @@ -642,6 +643,7 @@ func forwardResponse(w http.ResponseWriter, response *http.Response) error { buf := bufferPool.Get().([]byte) buf = buf[0:cap(buf)] _, err := io.CopyBuffer(w, response.Body, buf) + bufferPool.Put(buf) return err }