stream-labs / obs-studio-node

libOBS (OBS Studio) for Node.Js, Electron and similar tools
GNU General Public License v2.0
597 stars 99 forks source link

Fix memory manager source crash on shutdown #1384

Closed avoitenko-logitech closed 7 months ago

avoitenko-logitech commented 7 months ago

Description

Fixing crash with the following callstack

obs_source_get_settings (obs-source.c:3215)
updateSource (memory-manager.cpp:129)
mtx_do_lock (mutex.cpp:160)
MemoryManager::shutdownAllSources (memory-manager.cpp:376)
OBS_API::destroyOBS_API (nodeobs_api.cpp:1787)
RtlpAllocateHeapInternal
<unknown>
RtlFreeHeap
free_base
_Mtx_unlock (mutex.cpp:168)
std::_Mutex_base::unlock (mutex:95)
std::unique_lock<T>::{dtor} (mutex:226)
ipc::server::finalize (ipc-server.cpp:222)
main (main.cpp:324)

Motivation and Context

I've noticed that we are not incrementing reference counter when registering source in memory manager. That's why there always been a chance of crash because of dangling source pointer.

How Has This Been Tested?

Manually, windows build

Types of changes

Checklist: