From 68bceb957520f383fcecabc3a953adcb400d2031 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Wed, 29 Nov 2017 08:28:08 -0300 Subject: [PATCH] Fix race condition in event_subscriber.h --- atom/browser/api/event_subscriber.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/atom/browser/api/event_subscriber.h b/atom/browser/api/event_subscriber.h index 2f4f2396be46..8f09a61460a5 100644 --- a/atom/browser/api/event_subscriber.h +++ b/atom/browser/api/event_subscriber.h @@ -73,6 +73,13 @@ class EventSubscriber : internal::EventSubscriberBase { content::BrowserThread::UI, FROM_HERE, base::Bind( [](EventSubscriber* subscriber) { + { + // It is possible that this function will execute in the UI + // thread before the outer function has returned and destroyed + // its auto_lock. We need to acquire the lock before deleting + // or risk a crash. + base::AutoLock auto_lock(subscriber->handler_lock_); + } delete subscriber; }, ptr));