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.
Currently we use
append(s[:0:0], s...)
to clone a slice from an array pool. That approach comes with drawback if the slice happen to have zero len, the returning slice will share the same backing array of the array pool, causing array pool can not be freed until the returning slice become unreachable. More detail is declared here: golang/go#68488 (comment)This pattern was inspired from
slices.Clone
's CL that was first introduced in Go version v1.22.0. A new CL has been merged into Go's main branch to fix this issue but it seems without a backport request, so it might not be available until v1.24.0. If that's the case, people using v1.22.0 to v1.23.X are still being affected unless we do something about it. Since we typically clone a slice from an array pool, let's create our own clone function that better suite that case.