Skip to content

Commit

Permalink
src/libvisca-thread.cpp: Move add_ref before creating thread
Browse files Browse the repository at this point in the history
If the filter is created and removed in very short time, the thread
might call add_ref after the object was released by the main thread.
Though this situation never happen in a usual operation, the code should
be fixed to handle such scenario.
  • Loading branch information
norihiro committed Aug 2, 2024
1 parent ed761fe commit 133bf5b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/libvisca-thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ libvisca_thread::libvisca_thread()
zoom_got = 0;
pthread_mutex_init(&mutex, 0);

add_ref(); // release inside thread_main
pthread_t thread;
pthread_create(&thread, NULL, libvisca_thread::thread_main, (void*)this);
pthread_detach(thread);
Expand Down Expand Up @@ -79,9 +80,13 @@ void libvisca_thread::thread_connect()
void *libvisca_thread::thread_main(void *data)
{
auto *visca = (libvisca_thread*)data;
visca->add_ref();

// add_ref() was called just before creating this thread.

visca->thread_loop();

visca->release();

return NULL;
}

Expand Down

0 comments on commit 133bf5b

Please sign in to comment.