Skip to content

Commit 6b92612

Browse files
authored
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)
1 parent 0d333f1 commit 6b92612

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/coreclr/vm/eventpipe.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ void EventPipe::EnableViaEnvironmentVariables()
169169
int providerCnt = 0;
170170

171171
// Create EventPipeProviderConfiguration and start tracing.
172-
NewHolder<EventPipeProviderConfiguration> pProviders = nullptr;
172+
NewArrayHolder<EventPipeProviderConfiguration> pProviders = nullptr;
173+
NewArrayHolder<XplatEventLoggerConfiguration> pConfigurations = nullptr;
173174

174175
// If COMPlus_EnableEventPipe is set to 1 but no configuration was specified, enable EventPipe session
175176
// with the default provider configurations.
@@ -183,7 +184,6 @@ void EventPipe::EnableViaEnvironmentVariables()
183184
}
184185
else
185186
{
186-
auto configuration = XplatEventLoggerConfiguration();
187187
// Count how many providers there are to parse
188188
static WCHAR comma = W(',');
189189
while (*configToParse != '\0')
@@ -198,25 +198,28 @@ void EventPipe::EnableViaEnvironmentVariables()
198198
}
199199
configToParse = eventpipeConfig;
200200
pProviders = new EventPipeProviderConfiguration[providerCnt];
201+
pConfigurations = new XplatEventLoggerConfiguration[providerCnt];
201202
int i = 0;
202203
while (*configToParse != '\0')
203204
{
204205
auto end = wcschr(configToParse, comma);
205-
configuration.Parse(configToParse);
206+
pConfigurations[i].Parse(configToParse);
206207

207208
// if we find any invalid configuration, do not trace.
208-
if (!configuration.IsValid())
209+
if (!pConfigurations[i].IsValid())
209210
{
210211
return;
211212
}
212213

213-
pProviders[i++] = EventPipeProviderConfiguration(
214-
configuration.GetProviderName(),
215-
configuration.GetEnabledKeywordsMask(),
216-
configuration.GetLevel(),
217-
configuration.GetArgument()
214+
pProviders[i] = EventPipeProviderConfiguration(
215+
pConfigurations[i].GetProviderName(),
216+
pConfigurations[i].GetEnabledKeywordsMask(),
217+
pConfigurations[i].GetLevel(),
218+
pConfigurations[i].GetArgument()
218219
);
219220

221+
++i;
222+
220223
if (end == nullptr)
221224
{
222225
break;

0 commit comments

Comments
 (0)