From 6b9261218597802079ae99bdd11b3739e97e3bb6 Mon Sep 17 00:00:00 2001 From: Gleb Balykov Date: Thu, 17 Dec 2020 21:28:45 +0300 Subject: [PATCH] Fix memory errors related to EventPipe setup with COMPlus_EventPipeConfig (#44068) - XplatEventLoggerConfiguration configuration owns strings passed to EventPipeProviderConfiguration pProviders, and configurations are freed before pProviders are copied to EventPipeSessionProvider - NewArrayHolder shoud be used for pProviders to fix memory leak (delete[] instead of delete) --- src/coreclr/vm/eventpipe.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/coreclr/vm/eventpipe.cpp b/src/coreclr/vm/eventpipe.cpp index 77855ce..7673ca4 100644 --- a/src/coreclr/vm/eventpipe.cpp +++ b/src/coreclr/vm/eventpipe.cpp @@ -169,7 +169,8 @@ void EventPipe::EnableViaEnvironmentVariables() int providerCnt = 0; // Create EventPipeProviderConfiguration and start tracing. - NewHolder pProviders = nullptr; + NewArrayHolder pProviders = nullptr; + NewArrayHolder pConfigurations = nullptr; // If COMPlus_EnableEventPipe is set to 1 but no configuration was specified, enable EventPipe session // with the default provider configurations. @@ -183,7 +184,6 @@ void EventPipe::EnableViaEnvironmentVariables() } else { - auto configuration = XplatEventLoggerConfiguration(); // Count how many providers there are to parse static WCHAR comma = W(','); while (*configToParse != '\0') @@ -198,25 +198,28 @@ void EventPipe::EnableViaEnvironmentVariables() } configToParse = eventpipeConfig; pProviders = new EventPipeProviderConfiguration[providerCnt]; + pConfigurations = new XplatEventLoggerConfiguration[providerCnt]; int i = 0; while (*configToParse != '\0') { auto end = wcschr(configToParse, comma); - configuration.Parse(configToParse); + pConfigurations[i].Parse(configToParse); // if we find any invalid configuration, do not trace. - if (!configuration.IsValid()) + if (!pConfigurations[i].IsValid()) { return; } - pProviders[i++] = EventPipeProviderConfiguration( - configuration.GetProviderName(), - configuration.GetEnabledKeywordsMask(), - configuration.GetLevel(), - configuration.GetArgument() + pProviders[i] = EventPipeProviderConfiguration( + pConfigurations[i].GetProviderName(), + pConfigurations[i].GetEnabledKeywordsMask(), + pConfigurations[i].GetLevel(), + pConfigurations[i].GetArgument() ); + ++i; + if (end == nullptr) { break; -- 2.7.4