Skip to content

Commit 50c2192

Browse files
committed
(maint) Update to dispose stream once
1 parent c27556c commit 50c2192

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Source/GitReleaseManager/Configuration/ConfigurationProvider.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,22 @@ public static void WriteSample(string targetDirectory, IFileSystem fileSystem)
7373
if (!fileSystem.Exists(configFilePath))
7474
{
7575
_logger.Information("Writing sample file to '{ConfigFilePath}'", configFilePath);
76-
using (var stream = fileSystem.OpenWrite(configFilePath))
77-
using (var writer = new StreamWriter(stream))
76+
77+
// The following try/finally statements is to ensure that
78+
// any stream is not disposed more than once.
79+
Stream stream = null;
80+
try
81+
{
82+
stream = fileSystem.OpenWrite(configFilePath);
83+
using (var writer = new StreamWriter(stream))
84+
{
85+
stream = null;
86+
ConfigSerializer.WriteSample(writer);
87+
}
88+
}
89+
finally
7890
{
79-
ConfigSerializer.WriteSample(writer);
91+
stream?.Dispose();
8092
}
8193
}
8294
else

0 commit comments

Comments
 (0)