Skip to content

Commit f518c05

Browse files
authored
Fix not to create unnecessary thread_params (#76007)
1 parent 92c27e1 commit f518c05

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,28 +2012,43 @@ ep_rt_thread_create (
20122012

20132013
EX_TRY
20142014
{
2015-
rt_coreclr_thread_params_internal_t *thread_params = new (nothrow) rt_coreclr_thread_params_internal_t ();
2016-
if (thread_params) {
2017-
thread_params->thread_params.thread_type = thread_type;
2018-
if (thread_type == EP_THREAD_TYPE_SESSION || thread_type == EP_THREAD_TYPE_SAMPLING) {
2015+
if (thread_type == EP_THREAD_TYPE_SERVER)
2016+
{
2017+
DWORD thread_id = 0;
2018+
HANDLE server_thread = ::CreateThread (nullptr, 0, reinterpret_cast<LPTHREAD_START_ROUTINE>(thread_func), nullptr, 0, &thread_id);
2019+
if (server_thread != NULL)
2020+
{
2021+
if (id)
2022+
{
2023+
*reinterpret_cast<DWORD *>(id) = thread_id;
2024+
}
2025+
::CloseHandle (server_thread);
2026+
result = true;
2027+
}
2028+
}
2029+
else if (thread_type == EP_THREAD_TYPE_SESSION || thread_type == EP_THREAD_TYPE_SAMPLING)
2030+
{
2031+
rt_coreclr_thread_params_internal_t *thread_params = new (nothrow) rt_coreclr_thread_params_internal_t ();
2032+
if (thread_params)
2033+
{
2034+
thread_params->thread_params.thread_type = thread_type;
20192035
thread_params->thread_params.thread = SetupUnstartedThread ();
20202036
thread_params->thread_params.thread_func = reinterpret_cast<LPTHREAD_START_ROUTINE>(thread_func);
20212037
thread_params->thread_params.thread_params = params;
2022-
if (thread_params->thread_params.thread->CreateNewThread (0, ep_rt_thread_coreclr_start_func, thread_params)) {
2023-
thread_params->thread_params.thread->SetBackground (TRUE);
2024-
thread_params->thread_params.thread->StartThread ();
2038+
2039+
if (thread_params->thread_params.thread->CreateNewThread (0, ep_rt_thread_coreclr_start_func, thread_params))
2040+
{
20252041
if (id)
2042+
{
20262043
*reinterpret_cast<DWORD *>(id) = thread_params->thread_params.thread->GetThreadId ();
2044+
}
2045+
thread_params->thread_params.thread->SetBackground (TRUE);
2046+
thread_params->thread_params.thread->StartThread ();
20272047
result = true;
20282048
}
2029-
} else if (thread_type == EP_THREAD_TYPE_SERVER) {
2030-
DWORD thread_id = 0;
2031-
HANDLE server_thread = ::CreateThread (nullptr, 0, reinterpret_cast<LPTHREAD_START_ROUTINE>(thread_func), nullptr, 0, &thread_id);
2032-
if (server_thread != NULL) {
2033-
::CloseHandle (server_thread);
2034-
if (id)
2035-
*reinterpret_cast<DWORD *>(id) = thread_id;
2036-
result = true;
2049+
else
2050+
{
2051+
delete thread_params;
20372052
}
20382053
}
20392054
}

0 commit comments

Comments
 (0)