Fix a crash in the event tracing shutdown path
This CL fixes a crash that could happen when JSON event tracing is shutting down. The cause of the crash was the fact that the logger thread function was returning 'true', causing the platform thread to run it repeatedly even though that wasn't the intention. Usually the EventLogger::Stop() function would set the event requesting the logging thread to clean up and close the file, and then immediately call PlatformThread::Stop() which would stop the outer loop. The Log() function would only run once and everything behaves as expected. However, if a context switch happens between the shutdown_event_.Set() and logging_thread_.Stop() calls in EventLogger::Stop(), the logger thread function would close the file and exit the Log() method, while PlatformThread will rerun it again. So the Log() function runs twice, and the second time output_file_ is NULL which either causes the DCHECK to fail (in debug builds) or the fprintf() to crash with SIGSEGV (in release builds). The fix simply changes the return value of the thread function to false so it never runs twice. R=pthatcher@webrtc.org Review URL: https://codereview.webrtc.org/2168283002 . Cr-Commit-Position: refs/heads/master@{#13510}
This commit is contained in:
parent
d4e6cbdbbe
commit
843b6f503f
@ -197,7 +197,9 @@ class EventLogger final {
|
||||
|
||||
static bool EventTracingThreadFunc(void* params) {
|
||||
static_cast<EventLogger*>(params)->Log();
|
||||
return true;
|
||||
// False indicates that the thread function has done its job and doesn't need
|
||||
// to be restarted again. Log() runs its own internal loop.
|
||||
return false;
|
||||
}
|
||||
|
||||
static EventLogger* volatile g_event_logger = nullptr;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user