From b9e44c039889eb1e16d55a5699e6e53609a0a008 Mon Sep 17 00:00:00 2001 From: lateralusX Date: Tue, 8 Jun 2021 19:25:15 +0200 Subject: [PATCH] Fix memory corruption after free in EventPipe streaming thread. If streaming thread was aborted with an error it will disable the session. This is not the normal scenario, since most tools will explicit ask to close session, but if there is a network connectivity causing failures to write to stream, session will first be disabled and then it will write NULL into freed memory, causing heap corruption. Fix makes sure we reset streaming_thread before we eventually disable session, making sure it won't write into freed memory. --- src/native/eventpipe/ep-session.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/native/eventpipe/ep-session.c b/src/native/eventpipe/ep-session.c index 2f8a55b20b0fbc..973b20350448c4 100644 --- a/src/native/eventpipe/ep-session.c +++ b/src/native/eventpipe/ep-session.c @@ -71,11 +71,11 @@ EP_RT_DEFINE_THREAD_FUNC (streaming_thread) ep_rt_wait_event_set (&session->rt_thread_shutdown_event); EP_GCX_PREEMP_EXIT + session->streaming_thread = NULL; + if (!success) ep_disable ((EventPipeSessionID)session); - session->streaming_thread = NULL; - return (ep_rt_thread_start_func_return_t)0; }