Repository navigation
Dispose the XML reader in ImportXmlHelper - #28585
Open
Gabriel Carranza (GabeC2227) wants to merge 1 commit into
Open
Gabriel Carranza (GabeC2227) wants to merge 1 commit into
Gabriel Carranza (GabeC2227) wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
GabeC2227 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the XML reader cleanup change.
No open issues 🎉
What changed in this PR
Fixes XML reader cleanup in ImportXmlHelper, addressing item 4 of #15803 for Import-Clixml.
Changes:
- Disposes the XML reader and clears its reference after successful disposal.
- Preserves file-stream cleanup if reader disposal throws.
- Adds regression coverage for reader closure, reference clearing, and stream closure.
| File | Description |
|---|---|
| test/powershell/Modules/Microsoft.PowerShell.Utility/XMLCommand.Tests.ps1 | Adds a regression test for resource cleanup. |
| src/Microsoft.PowerShell.Commands.Utility/commands/utility/XmlCommands.cs | Disposes the reader while preserving file-stream cleanup. |
Review effort: Balanced
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR Summary
Dispose the XML reader owned by
ImportXmlHelperso thatImport-Clixmlproperly releases it during cleanup.PR Context
Addresses item 4 of #15803.
Previously,
ImportXmlHelperdisposed its file stream without disposing the associated XML reader or clearing its reference.This change disposes the XML reader, clears its reference following successful disposal, and preserves file-stream cleanup in a
finallyblock to ensure cleanup is attempted even if reader disposal throws.A regression test verifies that the XML reader reaches the
Closedstate, the helper clears its reader reference, and the underlying file stream closes.Testing and Validation
Expected Closed, but got Interactive).XMLCommand.Tests.ps1: 34 passed.Serialization.Tests.ps1: 6 passed, 1 pre-existing pending.ConvertTo-Xml.Tests.ps1: 11 passed.DefaultCommands.Tests.ps1: 290 passed.StopProcessingtest passed.git diff --checkpassed.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header