Skip to content

Convert using statement to using declaration for ReturnableBufferWriter in GetMemoryUsageInBytes#7464

Merged
evgenyfedorov2 merged 1 commit into
mainfrom
copilot/fix-returnable-buffer-writer
Apr 13, 2026
Merged

Convert using statement to using declaration for ReturnableBufferWriter in GetMemoryUsageInBytes#7464
evgenyfedorov2 merged 1 commit into
mainfrom
copilot/fix-returnable-buffer-writer

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

Summary

In LinuxUtilizationParserCgroupV2.cs, the GetMemoryUsageInBytes method used a using block statement for ReturnableBufferWriter<char>, which disposed the buffer at the end of the block while memoryFile (a ReadOnlySpan<char> pointing into the buffer) was still used afterward.

This converts it to a using declaration, extending the buffer's lifetime to the method scope and making the code consistent with all other usages of ReturnableBufferWriter in this file and the codebase.

Changes

  • Changed using (ReturnableBufferWriter<char> bufferWriter = new(_sharedBufferWriterPool)) to using ReturnableBufferWriter<char> bufferWriter = new(_sharedBufferWriterPool);
  • Removed the unnecessary curly braces that scoped the block
  • Inlined the memoryFile declaration with its assignment
Microsoft Reviewers: Open in CodeFlow

…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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 using statement block with a using declaration so the pooled buffer isn’t disposed before memoryFile is processed.
  • Removed the extra scope braces and inlined the memoryFile initialization.

@evgenyfedorov2 evgenyfedorov2 merged commit 2e9488b into main Apr 13, 2026
14 checks passed
@evgenyfedorov2 evgenyfedorov2 deleted the copilot/fix-returnable-buffer-writer branch April 13, 2026 15:38
@tarekgh tarekgh added this to the 11.0 milestone Apr 13, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators May 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants