XHTTP client: Fix potential memory leak in stream-up/one (#6095)

Fixes https://github.com/XTLS/Xray-core/pull/6087#issuecomment-4402474552
This commit is contained in:
风扇滑翔翼 2026-05-10 00:54:57 +08:00 committed by GitHub
parent eb32d166af
commit 9d9eaf399f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -71,6 +71,7 @@ func (c *DefaultDialerClient) OpenStream(ctx context.Context, url string, sessio
errors.LogInfoInner(ctx, err, "failed to "+method+" "+url)
}
gotConn.Close()
common.Close(body)
wrc.Close()
return
}
@ -80,6 +81,7 @@ func (c *DefaultDialerClient) OpenStream(ctx context.Context, url string, sessio
if resp.StatusCode != 200 || uploadOnly { // stream-up
io.Copy(io.Discard, resp.Body)
resp.Body.Close() // if it is called immediately, the upload will be interrupted also
common.Close(body)
wrc.Close()
return
}