Skip to content

Commit 0f980e2

Browse files
committed
C#: Properly dispose diagnostic writer objects
1 parent d7e5149 commit 0f980e2

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

cpp/autobuilder/Semmle.Autobuild.Cpp/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static int Main()
1717
try
1818
{
1919
Console.WriteLine("CodeQL C++ autobuilder");
20-
var builder = new CppAutobuilder(actions, options);
20+
using var builder = new CppAutobuilder(actions, options);
2121
return builder.AttemptBuild();
2222
}
2323
catch (InvalidEnvironmentException ex)

csharp/autobuilder/Semmle.Autobuild.CSharp/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static int Main()
1717
try
1818
{
1919
Console.WriteLine("CodeQL C# autobuilder");
20-
var builder = new CSharpAutobuilder(actions, options);
20+
using var builder = new CSharpAutobuilder(actions, options);
2121
return builder.AttemptBuild();
2222
}
2323
catch (InvalidEnvironmentException ex)

csharp/autobuilder/Semmle.Autobuild.Shared/Autobuilder.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public interface IAutobuilder<out TAutobuildOptions> where TAutobuildOptions : A
9292
/// The overall design is intended to be extensible so that in theory,
9393
/// it should be possible to add new build rules without touching this code.
9494
/// </summary>
95-
public abstract class Autobuilder<TAutobuildOptions> : IAutobuilder<TAutobuildOptions> where TAutobuildOptions : AutobuildOptionsShared
95+
public abstract class Autobuilder<TAutobuildOptions> : IDisposable, IAutobuilder<TAutobuildOptions> where TAutobuildOptions : AutobuildOptionsShared
9696
{
9797
/// <summary>
9898
/// Full file paths of files found in the project directory, as well as
@@ -351,6 +351,20 @@ protected BuildScript AutobuildFailure() =>
351351
}
352352
});
353353

354+
public void Dispose()
355+
{
356+
Dispose(true);
357+
GC.SuppressFinalize(this);
358+
}
359+
360+
protected virtual void Dispose(bool disposing)
361+
{
362+
if (disposing)
363+
{
364+
(diagnostics as IDisposable)?.Dispose();
365+
}
366+
}
367+
354368
/// <summary>
355369
/// Value of CODEQL_EXTRACTOR_<LANG>_ROOT environment variable.
356370
/// </summary>

0 commit comments

Comments
 (0)