From 57e8f845186691a0938e3d8c815726afad2a0096 Mon Sep 17 00:00:00 2001 From: Gleb Balykov Date: Tue, 8 Dec 2020 21:53:49 +0300 Subject: [PATCH] Fix memory errors related to EventPipe setup with COMPlus_EventPipeConfig - 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 77855ce1271341..7673ca498c036a 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;