Proxy: Fix resource leak in ParseBody. v8.0.26 - #4659
Merged
winlinvip merged 5 commits intoAug 18, 2026
Conversation
winlinvip
force-pushed
the
develop
branch
3 times, most recently
from
May 17, 2026 16:09
6ce415e to
6ee6f1c
Compare
…arseBody 1. BuildStreamURL: net.ParseIP() returns nil for non-IP hostnames (e.g., "example.com"), then calling nil.To4() panics. Add nil check before calling To4(). 2. ParseBody: defer r.Close() is placed after the ReadAll error check. If ReadAll fails, the function returns early without closing r, causing a resource leak. Move defer to the top of the function.
suzp1984
force-pushed
the
fix/utils-nil-pointer-and-resource-leak
branch
from
May 19, 2026 03:19
b9d182c to
e124f9f
Compare
Contributor
|
I rebased your branch to develop branch. |
suzp1984
approved these changes
May 19, 2026
Add TestParseBody_CloseCalledOnReadError to verify r.Close() is called even when ReadAll fails (resource leak fix). Enhance TestBuildStreamURL with: - Comment explaining the example.com case would panic before the nil pointer fix (net.ParseIP returns nil for non-IP hostnames) - IPv6 test cases to verify ip.To4() check works correctly - Clarifying comments for each test case category
Contributor
|
One more thing, I added UT to cover this PR. |
winlinvip
added a commit
that referenced
this pull request
Aug 18, 2026
Backports #4659 (`69cbfe5e9`) to the SRS 7.0 release branch. `ParseBody` deferred `r.Close()` only after `io.ReadAll(r)` succeeded. When `io.ReadAll` returned an error, the function returned before registering the deferred close, leaving the request/body reader open. --- Co-authored-by: sevico <swkhack@gmail.com> Co-authored-by: Jacob Su <suzp1984@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ParseBodyininternal/utils/utils.godefersr.Close()only afterio.ReadAll(r)succeeds. Ifio.ReadAllreturns an error, the function returns before registering the deferred close, so the request/body reader is left open.Solution
Move
defer r.Close()to the top ofParseBody, before reading the body, so all return paths close the reader.