Skip to content

Commit

Permalink
Always disposing context
Browse files Browse the repository at this point in the history
  • Loading branch information
eddynaka committed Mar 1, 2021
1 parent 44f0dff commit 47644bd
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,14 @@ private async Task<bool> WriteResultsAsync(TContext rootContext)
// processed, we just ignore this notification.
if (currentIndex > item) { break; }

TContext context;
TContext context = default;
bool didAnalyze;
try
{
context = _fileContexts[currentIndex];
didAnalyze = false;

while (context?.AnalysisComplete == true)
while (context?.AnalysisComplete == true && !didAnalyze)
{
var cachingLogger = (CachingLogger)context.Logger;
IDictionary<ReportingDescriptor, IList<Result>> results = cachingLogger.Results;
Expand Down Expand Up @@ -277,22 +279,20 @@ private async Task<bool> WriteResultsAsync(TContext rootContext)

RuntimeErrors |= context.RuntimeErrors;

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

context = currentIndex < (_fileContexts.Count - 1)
? context = _fileContexts[currentIndex + 1]
: default;

currentIndex++;
didAnalyze = true;
}
}
catch (Exception e)
{
context = default;
RuntimeErrors |= Errors.LogUnhandledEngineException(rootContext, e);
ThrowExitApplicationException(context, ExitReason.ExceptionWritingToLogFile, e);
}
finally
{
context?.Dispose();
}
}
}

Expand Down

0 comments on commit 47644bd

Please sign in to comment.