Skip to content

Commit b4fd433

Browse files
author
Michael Fabian Dirks
committed
Fix rare lockup on startup and missing object deallocation
* This fixes the destructor for BrowserManager::Impl, which was leaking four objects every time it was called. * Also fixes a startup freeze caused by the manager thread executing too early, so that threadAlive is still false: 1. pthread_create is called for the manager thread, does not yet return. 2. The manager thread immediately runs, see the 'if (!threadAlive) return;' check and terminates. 3. pthread_create returns 0 (success), threadAlive is set to true. Source is created, but we no longer have a manager to run events. 4. Program hangs on startup.
1 parent 96f614a commit b4fd433

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

obs-browser/browser-manager-base.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ BrowserManager::Impl::Impl()
112112

113113
BrowserManager::Impl::~Impl()
114114
{
115-
os_event_init(&dispatchEvent, OS_EVENT_TYPE_AUTO);
116-
pthread_mutex_init(&dispatchLock, nullptr);
115+
os_event_destroy(dispatchEvent);
116+
pthread_mutex_destroy(&dispatchLock);
117117
}
118118

119119
int BrowserManager::Impl::CreateBrowser(
@@ -366,6 +366,7 @@ void BrowserManager::Impl::DispatchJSEvent(const char *eventName, const char *js
366366
void
367367
BrowserManager::Impl::Startup()
368368
{
369+
pthread_mutex_lock(&dispatchLock);
369370
int ret = pthread_create(&managerThread, nullptr,
370371
browserManagerEntry, this);
371372

@@ -378,6 +379,7 @@ BrowserManager::Impl::Startup()
378379
else {
379380
threadAlive = true;
380381
}
382+
pthread_mutex_unlock(&dispatchLock);
381383

382384
return;
383385
}

0 commit comments

Comments
 (0)