Skip to content

Guard finalizer against partial construction - #447

Merged
Ben (benmwatson) merged 1 commit into
microsoft:masterfrom
scottlerch:sclerch/fix-partial-construction-finalizer
Aug 10, 2026
Merged

Guard finalizer against partial construction#447
Ben (benmwatson) merged 1 commit into
microsoft:masterfrom
scottlerch:sclerch/fix-partial-construction-finalizer

Conversation

@scottlerch

Copy link
Copy Markdown
Member

Summary

Prevent RecyclableMemoryStream finalization from throwing when construction fails before required fields are initialized.

Changes

  • Return immediately from Dispose(bool) when either memoryManager or blocks is null.
  • Add deterministic regression coverage for uninitialized streams and each meaningful one-field-initialized state.
  • Suppress finalization in test cleanup even if an assertion fails.

Testing

  • dotnet build Microsoft.IO.RecyclableMemoryStream.sln --configuration Debug --no-restore
  • dotnet test Microsoft.IO.RecyclableMemoryStream.sln --configuration Debug --no-build --no-restore
  • Result: 1,317 passed, 9 skipped, 0 failed.

Fixes #446

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@benmwatson
Ben (benmwatson) merged commit 6436162 into microsoft:master Aug 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Finalizer can throw after RecyclableMemoryStream construction fails

2 participants