From 44f0dffae466ae5db437fc006cae9301237047e4 Mon Sep 17 00:00:00 2001 From: Eddy Nakamura Date: Mon, 1 Mar 2021 01:11:24 -0300 Subject: [PATCH] Disposing after use (#2302) --- .../Sdk/MultithreadedAnalyzeCommandBase.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs index 6fc36d25e..07475472f 100644 --- a/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs +++ b/src/Sarif.Driver/Sdk/MultithreadedAnalyzeCommandBase.cs @@ -27,6 +27,7 @@ public abstract class MultithreadedAnalyzeCommandBase : 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; @@ -84,7 +85,7 @@ public override int Run(TOptions options) if (!(ex is ExitApplicationException)) { - // 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; @@ -220,20 +221,20 @@ private async Task 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> results = cachingLogger.Results; if (results?.Count > 0) @@ -276,6 +277,7 @@ private async Task WriteResultsAsync(TContext rootContext) RuntimeErrors |= context.RuntimeErrors; + context.Dispose(); _fileContexts[currentIndex] = default; context = currentIndex < (_fileContexts.Count - 1) @@ -1017,7 +1019,7 @@ protected virtual ISet> InitializeSkimmers(ISet> disabledSkimmers = new SortedSet>(SkimmerIdComparer.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 skimmer in skimmers) {