diff --git a/src/coreclr/src/vm/eventpipe.cpp b/src/coreclr/src/vm/eventpipe.cpp index dea3b1e493c1745500a527572e1d8c74dd8d2424..0458be885448a136bd49477732cff6f5a67bf0de 100644 --- a/src/coreclr/src/vm/eventpipe.cpp +++ b/src/coreclr/src/vm/eventpipe.cpp @@ -259,6 +259,11 @@ void EventPipe::Shutdown() EX_CATCH {} EX_END_CATCH(SwallowAllExceptions); + // Remove EventPipeEventSource first since it tries to use the data structures that we remove below. + // We need to do this after disabling sessions since those try to write to EventPipeEventSource. + delete s_pEventSource; + s_pEventSource = nullptr; + EventPipeConfiguration *pConfig = s_pConfig; EventPipeSessions *pSessions = s_pSessions; @@ -271,8 +276,6 @@ void EventPipe::Shutdown() // Free resources. delete pConfig; delete pSessions; - delete s_pEventSource; - s_pEventSource = nullptr; } EventPipeSessionID EventPipe::Enable(