Skip to content

Guard finalizer against partial construction - #447

Open
Scott Lerch (scottlerch) wants to merge 1 commit into
microsoft:masterfrom
scottlerch:sclerch/fix-partial-construction-finalizer
Open

Guard finalizer against partial construction#447
Scott Lerch (scottlerch) wants to merge 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>
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

1 participant