From 759dfa63e4c1b4c354df188680e2bff1c9ba64d1 Mon Sep 17 00:00:00 2001 From: Petr Vaganov Date: Tue, 9 Jun 2026 14:09:25 +0700 Subject: [PATCH] fix HANDLE_LEAK in websocket_proxy Found by the static analyzer Svace (ISP RAS). Handle 'requestBodyR' is created at websocket_proxy.go:186 by calling function 'io.Pipe' and lost at websocket_proxy.go:190. Handle 'responseBodyR' is created at websocket_proxy.go:212 by calling function 'io.Pipe' and lost at websocket_proxy.go:304. Signed-off-by: Petr Vaganov --- wsproxy/websocket_proxy.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wsproxy/websocket_proxy.go b/wsproxy/websocket_proxy.go index 7092162..6081579 100644 --- a/wsproxy/websocket_proxy.go +++ b/wsproxy/websocket_proxy.go @@ -184,9 +184,11 @@ func (p *Proxy) proxy(w http.ResponseWriter, r *http.Request) { defer cancelFn() requestBodyR, requestBodyW := io.Pipe() + defer requestBodyR.Close() request, err := http.NewRequestWithContext(r.Context(), r.Method, r.URL.String(), requestBodyR) if err != nil { p.logger.Warnln("error preparing request:", err) + defer requestBodyW.Close() return } if swsp := r.Header.Get("Sec-WebSocket-Protocol"); swsp != "" { @@ -210,6 +212,7 @@ func (p *Proxy) proxy(w http.ResponseWriter, r *http.Request) { } responseBodyR, responseBodyW := io.Pipe() + defer responseBodyR.Close() response := newInMemoryResponseWriter(responseBodyW) go func() { <-ctx.Done()