Convert using statement to using declaration for ReturnableBufferWriter in GetMemoryUsageInBytes#7464
Merged
Conversation
…er in GetMemoryUsageInBytes Agent-Logs-Url: https://github.com/dotnet/extensions/sessions/e3d7d2a5-8d09-4e6c-87f0-98b7f8dc7726 Co-authored-by: evgenyfedorov2 <25526458+evgenyfedorov2@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
evgenyfedorov2
April 13, 2026 07:29
View session
evgenyfedorov2
approved these changes
Apr 13, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a buffer lifetime issue in the Linux cgroup v2 memory utilization parser by ensuring a pooled ReturnableBufferWriter<char> remains valid while a ReadOnlySpan<char> that points into it is being consumed.
Changes:
- Replaced a
usingstatement block with ausingdeclaration so the pooled buffer isn’t disposed beforememoryFileis processed. - Removed the extra scope braces and inlined the
memoryFileinitialization.
tarekgh
approved these changes
Apr 13, 2026
This was referenced May 12, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
In
LinuxUtilizationParserCgroupV2.cs, theGetMemoryUsageInBytesmethod used ausingblock statement forReturnableBufferWriter<char>, which disposed the buffer at the end of the block whilememoryFile(aReadOnlySpan<char>pointing into the buffer) was still used afterward.This converts it to a
usingdeclaration, extending the buffer's lifetime to the method scope and making the code consistent with all other usages ofReturnableBufferWriterin this file and the codebase.Changes
using (ReturnableBufferWriter<char> bufferWriter = new(_sharedBufferWriterPool))tousing ReturnableBufferWriter<char> bufferWriter = new(_sharedBufferWriterPool);memoryFiledeclaration with its assignmentMicrosoft Reviewers: Open in CodeFlow