Skip to content

Commit 627d75b

Browse files
committed
Dispose stream
1 parent 99a80b9 commit 627d75b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public async Task<ReadResult> ReadAsync(Stream input,
2929
if (input is MemoryStream memoryStream)
3030
{
3131
return Read(memoryStream, settings);
32-
} else {
32+
}
33+
else
34+
{
3335
using var preparedStream = new MemoryStream();
3436
await input.CopyToAsync(preparedStream, copyBufferSize, cancellationToken);
3537
preparedStream.Position = 0;
@@ -39,14 +41,15 @@ public async Task<ReadResult> ReadAsync(Stream input,
3941

4042
/// <inheritdoc/>
4143
public ReadResult Read(MemoryStream input,
42-
OpenApiReaderSettings settings = null)
44+
OpenApiReaderSettings settings = null)
4345
{
4446
JsonNode jsonNode;
4547

4648
// Parse the YAML text in the TextReader into a sequence of JsonNodes
4749
try
4850
{
49-
jsonNode = LoadJsonNodesFromYamlDocument(new StreamReader(input)); // Should we leave the stream open?
51+
using var stream = new StreamReader(input);
52+
jsonNode = LoadJsonNodesFromYamlDocument(stream);
5053
}
5154
catch (JsonException ex)
5255
{
@@ -73,7 +76,8 @@ public T ReadFragment<T>(MemoryStream input,
7376
// Parse the YAML
7477
try
7578
{
76-
jsonNode = LoadJsonNodesFromYamlDocument(new StreamReader(input));
79+
using var stream = new StreamReader(input);
80+
jsonNode = LoadJsonNodesFromYamlDocument(stream);
7781
}
7882
catch (JsonException ex)
7983
{

0 commit comments

Comments
 (0)