Skip to content

Commit 7270a89

Browse files
committed
Dispose preparedStream properly
1 parent ee63758 commit 7270a89

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Microsoft.OpenApi/Reader/OpenApiModelFactory.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,15 @@ public static async Task<ReadResult> LoadAsync(Stream input, string format = nul
124124
}
125125

126126
// Use StreamReader to process the prepared stream (buffered for YAML, direct for JSON)
127-
var result = await InternalLoadAsync(preparedStream, format, settings, cancellationToken).ConfigureAwait(false);
128-
if (!settings.LeaveStreamOpen)
127+
using (preparedStream)
129128
{
130-
input.Dispose();
131-
preparedStream.Dispose();
129+
var result = await InternalLoadAsync(preparedStream, format, settings, cancellationToken).ConfigureAwait(false);
130+
if (!settings.LeaveStreamOpen)
131+
{
132+
input.Dispose();
133+
}
134+
return result;
132135
}
133-
134-
return result;
135136
}
136137

137138
/// <summary>

0 commit comments

Comments
 (0)