From c6a316714923ab6d79d4f9bde10915008d8ec079 Mon Sep 17 00:00:00 2001 From: Omair Majid Date: Mon, 10 Jun 2024 18:53:17 -0400 Subject: [PATCH] Dispose XmlReader in XmlRunSettingsUtilities The existing code disposes the underlying stream, but not the XmlReader itself, even though the XmlReader is an IDisposable too. --- .../Utilities/XmlRunSettingsUtilities.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs b/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs index 2912dbe98f..8926383223 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Utilities/XmlRunSettingsUtilities.cs @@ -233,7 +233,7 @@ public static bool IsInProcDataCollectionEnabled(string? runSettingsXml) try { using var stringReader = new StringReader(runSettingsXml); - var reader = XmlReader.Create(stringReader, ReaderSettings); + using var reader = XmlReader.Create(stringReader, ReaderSettings); // read to the fist child XmlReaderUtilities.ReadToRootNode(reader); @@ -277,7 +277,7 @@ public static bool IsInProcDataCollectionEnabled(string? runSettingsXml) runSettingsXml = runSettingsXml.Trim(); using StringReader stringReader1 = new(runSettingsXml); - XmlReader reader = XmlReader.Create(stringReader1, ReaderSettings); + using XmlReader reader = XmlReader.Create(stringReader1, ReaderSettings); // read to the fist child XmlReaderUtilities.ReadToRootNode(reader); @@ -357,7 +357,7 @@ internal static void ThrowOnNoAttributes(XmlReader reader) try { using var stringReader = new StringReader(settingsXml); - XmlReader reader = XmlReader.Create(stringReader, ReaderSettings); + using XmlReader reader = XmlReader.Create(stringReader, ReaderSettings); // read to the fist child XmlReaderUtilities.ReadToRootNode(reader);