From baca1eb823b1833ec1aa6c626bdc29597be4f690 Mon Sep 17 00:00:00 2001 From: ABykiev Date: Mon, 29 Jul 2024 23:06:34 +0300 Subject: [PATCH] Fix memory leak in VerticalMetricsTable This PR fixes memory leak in VerticalMetricsTable --- src/SixLabors.Fonts/BigEndianBinaryReader.cs | 2 +- src/SixLabors.Fonts/Tables/General/VerticalMetricsTable.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/SixLabors.Fonts/BigEndianBinaryReader.cs b/src/SixLabors.Fonts/BigEndianBinaryReader.cs index fee870b5..e164093b 100644 --- a/src/SixLabors.Fonts/BigEndianBinaryReader.cs +++ b/src/SixLabors.Fonts/BigEndianBinaryReader.cs @@ -12,7 +12,7 @@ namespace SixLabors.Fonts; /// BinaryReader using big-endian encoding. /// [DebuggerDisplay("Start: {StartOfStream}, Position: {BaseStream.Position}")] -internal class BigEndianBinaryReader : IDisposable +internal sealed class BigEndianBinaryReader : IDisposable { /// /// Buffer used for temporary storage before conversion into primitives diff --git a/src/SixLabors.Fonts/Tables/General/VerticalMetricsTable.cs b/src/SixLabors.Fonts/Tables/General/VerticalMetricsTable.cs index 25ad3dbb..6b7fc648 100644 --- a/src/SixLabors.Fonts/Tables/General/VerticalMetricsTable.cs +++ b/src/SixLabors.Fonts/Tables/General/VerticalMetricsTable.cs @@ -47,7 +47,10 @@ internal short GetTopSideBearing(int glyphIndex) return null; } - return Load(binaryReader, headTable.NumberOfVMetrics, profileTable.GlyphCount); + using (binaryReader) + { + return Load(binaryReader, headTable.NumberOfVMetrics, profileTable.GlyphCount); + } } public static VerticalMetricsTable Load(BigEndianBinaryReader reader, int metricCount, int glyphCount)