Commit 8b55d66d authored by Tristan Matthews's avatar Tristan Matthews

* #18668: daemon: only join threads that have been created

If you try and join a NULL thread, you will segfault.
parent 7d3a53ff
......@@ -31,12 +31,13 @@
#include "eventthread.h"
#include "voiplink.h"
EventThread::EventThread(VoIPLink *link) : link_(link)
EventThread::EventThread(VoIPLink *link) : link_(link), thread_(0)
{}
EventThread::~EventThread()
{
pthread_join(thread_, NULL);
if (thread_)
pthread_join(thread_, NULL);
}
void EventThread::start()
......
......@@ -223,7 +223,7 @@ VideoReceiveThread::VideoReceiveThread(const std::string &id, const std::map<str
avioContext_(avio_alloc_context(sdpBuffer_.get(), SDP_BUFFER_SIZE, 0,
reinterpret_cast<void*>(static_cast<std::istream*>(&stream_)),
&readFunction, 0, 0), &av_free),
thread_()
thread_(0)
{
interruptCb_.callback = interruptCb;
interruptCb_.opaque = this;
......@@ -347,7 +347,8 @@ VideoReceiveThread::~VideoReceiveThread()
set_false_atomic(&threadRunning_);
Manager::instance().getVideoControls()->stoppedDecoding(id_, sink_.openedName());
// waits for the run() method (in separate thread) to return
pthread_join(thread_, NULL);
if (thread_)
pthread_join(thread_, NULL);
}
void VideoReceiveThread::setRequestKeyFrameCallback(void (*cb)(const std::string &))
......
......@@ -347,7 +347,7 @@ VideoSendThread::VideoSendThread(const std::string &id, const std::map<string, s
interruptCb_(),
threadRunning_(false),
forceKeyFrame_(0),
thread_(),
thread_(0),
frameNumber_(0)
{
interruptCb_.callback = interruptCb;
......@@ -562,7 +562,8 @@ VideoSendThread::~VideoSendThread()
{
set_false_atomic(&threadRunning_);
Manager::instance().getVideoControls()->stoppedDecoding(id_, sink_.openedName());
pthread_join(thread_, NULL);
if (thread_)
pthread_join(thread_, NULL);
}
void VideoSendThread::forceKeyFrame()
......
......@@ -67,7 +67,7 @@ static int is_v4l2(struct udev_device *dev)
}
VideoV4l2ListThread::VideoV4l2ListThread() : devices_(),
thread_(), mutex_(), udev_(0),
thread_(0), mutex_(), udev_(0),
udev_mon_(0), probing_(false)
{
pthread_mutex_init(&mutex_, NULL);
......@@ -214,7 +214,8 @@ start:
VideoV4l2ListThread::~VideoV4l2ListThread()
{
probing_ = false;
pthread_join(thread_, NULL);
if (thread_)
pthread_join(thread_, NULL);
if (udev_mon_)
udev_monitor_unref(udev_mon_);
if (udev_)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment