Skip to content

Commit

Permalink
Disposing after use (#2302)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddynaka committed Mar 1, 2021
1 parent 7262308 commit 44f0dff
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public abstract class MultithreadedAnalyzeCommandBase<TContext, TOptions> : Plug
// ways depending on whether output is captured to a log file disk or not. In the latter case,
// the captured output is useful to verify behavior.
internal bool _captureConsoleOutput;

internal ConsoleLogger _consoleLogger;

private Run _run;
Expand Down Expand Up @@ -84,7 +85,7 @@ public override int Run(TOptions options)

if (!(ex is ExitApplicationException<ExitReason>))
{
// These exceptions escaped our net and must be logged here
// These exceptions escaped our net and must be logged here
RuntimeErrors |= Errors.LogUnhandledEngineException(_rootContext, ex);
}
ExecutionException = ex;
Expand Down Expand Up @@ -220,20 +221,20 @@ private async Task<bool> WriteResultsAsync(TContext rootContext)
itemsSeen.Add(item);

// This condition can occur if currentIndex moves
// ahead in array processing due to operations
// against it by other threads. For this case,
// since the relevant file has already been
// ahead in array processing due to operations
// against it by other threads. For this case,
// since the relevant file has already been
// processed, we just ignore this notification.
if (currentIndex > item) { break; }

TContext context = default;
TContext context;
try
{
context = _fileContexts[currentIndex];

while (context?.AnalysisComplete == true)
{
CachingLogger cachingLogger = ((CachingLogger)context.Logger);
var cachingLogger = (CachingLogger)context.Logger;
IDictionary<ReportingDescriptor, IList<Result>> results = cachingLogger.Results;

if (results?.Count > 0)
Expand Down Expand Up @@ -276,6 +277,7 @@ private async Task<bool> WriteResultsAsync(TContext rootContext)

RuntimeErrors |= context.RuntimeErrors;

context.Dispose();
_fileContexts[currentIndex] = default;

context = currentIndex < (_fileContexts.Count - 1)
Expand Down Expand Up @@ -1017,7 +1019,7 @@ protected virtual ISet<Skimmer<TContext>> InitializeSkimmers(ISet<Skimmer<TConte
{
SortedSet<Skimmer<TContext>> disabledSkimmers = new SortedSet<Skimmer<TContext>>(SkimmerIdComparer<TContext>.Instance);

// ONE-TIME initialization of skimmers. Do not call
// ONE-TIME initialization of skimmers. Do not call
// Initialize more than once per skimmer instantiation
foreach (Skimmer<TContext> skimmer in skimmers)
{
Expand Down

0 comments on commit 44f0dff

Please sign in to comment.