Skip to content

Commit 456f379

Browse files
Fix memory leak in LiftWriter (#1484)
* Dispose temporary XML readers in LiftWriter Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: jasonleenaylor <[email protected]>
1 parent d010103 commit 456f379

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2525
- [SIL.Core.Clearshare] New tests MetadataBareTests are based on previous MetadataTests in SIL.Windows.Forms.Clearshare. The tests were updated to use ImageSharp instead of Winforms for handling images.
2626

2727
### Fixed
28+
- [SIL.DictionaryServices] Fix memory leak in LiftWriter
2829
- [SIL.WritingSystems] Fix IetfLanguageTag.GetGeneralCode to handle cases when zh-CN or zh-TW is a prefix and not the whole string.
2930
- [SIL.Windows.Forms] Prevent BetterLabel from responding to OnTextChanged when it has been disposed.
3031
- [SIL.Windows.Forms] Prevent ContributorsListControl.GetContributionFromRow from throwing an exception when the DataGridView has no valid rows selected.

SIL.DictionaryServices/Lift/LiftWriter.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -726,19 +726,21 @@ protected void WriteLanguageFormsInWrapper(IEnumerable<LanguageForm> forms, stri
726726

727727
string scaryUnicodeEscaped = form.Form.EscapeAnyUnicodeCharactersIllegalInXml();
728728
string safeFromScaryUnicodeSoItStaysEscaped = scaryUnicodeEscaped.Replace("&#x", "");
729-
XmlReader testerForWellFormedness = XmlReader.Create(new StringReader("<temp>" + safeFromScaryUnicodeSoItStaysEscaped + "</temp>"));
730-
731729
bool isTextWellFormedXml = true;
732-
try
730+
using (var stringReader = new StringReader("<temp>" + safeFromScaryUnicodeSoItStaysEscaped + "</temp>"))
731+
using (var testerForWellFormedness = XmlReader.Create(stringReader))
733732
{
734-
while (testerForWellFormedness.Read())
733+
try
735734
{
736-
//Just checking for well formed XML
735+
while (testerForWellFormedness.Read())
736+
{
737+
//Just checking for well formed XML
738+
}
739+
}
740+
catch
741+
{
742+
isTextWellFormedXml = false;
737743
}
738-
}
739-
catch
740-
{
741-
isTextWellFormedXml = false;
742744
}
743745

744746
if (isTextWellFormedXml)

0 commit comments

Comments
 (0)