From a6a3d382d9a5fabeda6983f90226939228a14cfe Mon Sep 17 00:00:00 2001 From: Brian Robbins Date: Sat, 3 Mar 2018 20:56:43 -0800 Subject: [PATCH] Fix use of EventPipeConfiguration after it has been freed on shutdown. (#16704) --- src/vm/eventpipe.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/vm/eventpipe.cpp b/src/vm/eventpipe.cpp index e413713..ab13738 100644 --- a/src/vm/eventpipe.cpp +++ b/src/vm/eventpipe.cpp @@ -237,7 +237,10 @@ void EventPipe::Shutdown() } CONTRACTL_END; - // We are shutting down, so if diasabling EventPipe throws, we need to move along anyway + // Mark tracing as no longer initialized. + s_tracingInitialized = false; + + // We are shutting down, so if disabling EventPipe throws, we need to move along anyway. EX_TRY { Disable(); @@ -245,16 +248,19 @@ void EventPipe::Shutdown() EX_CATCH { } EX_END_CATCH(SwallowAllExceptions); - if(s_pConfig != NULL) - { - delete(s_pConfig); - s_pConfig = NULL; - } - if(s_pBufferManager != NULL) - { - delete(s_pBufferManager); - s_pBufferManager = NULL; - } + // Save pointers to the configuration and buffer manager. + EventPipeConfiguration *pConfig = s_pConfig; + EventPipeBufferManager *pBufferManager = s_pBufferManager; + + // Set the static pointers to NULL so that the rest of the EventPipe knows that they are no longer available. + // Flush process write buffers to make sure other threads can see the change. + s_pConfig = NULL; + s_pBufferManager = NULL; + FlushProcessWriteBuffers(); + + // Free the configuration and buffer manager. + delete(pConfig); + delete(pBufferManager); } void EventPipe::Enable( -- 2.7.4