mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
SafeThread: Avoid use-after-free risk in thread shutdown (#1355)
Use shared_ptr to keep data alive until the thread has terminated.
This commit is contained in:
@@ -865,10 +865,7 @@ void MjpegServerImpl::ServerThreadMain() {
|
||||
}
|
||||
|
||||
// Start it if not already started
|
||||
{
|
||||
auto thr = it->GetThread();
|
||||
if (!thr) it->Start(new ConnThread{GetName()});
|
||||
}
|
||||
it->Start(GetName());
|
||||
|
||||
auto nstreams =
|
||||
std::count_if(m_connThreads.begin(), m_connThreads.end(),
|
||||
|
||||
@@ -94,10 +94,7 @@ Notifier::Notifier() { s_destroyed = false; }
|
||||
|
||||
Notifier::~Notifier() { s_destroyed = true; }
|
||||
|
||||
void Notifier::Start() {
|
||||
auto thr = m_owner.GetThread();
|
||||
if (!thr) m_owner.Start(new Thread(m_on_start, m_on_exit));
|
||||
}
|
||||
void Notifier::Start() { m_owner.Start(m_on_start, m_on_exit); }
|
||||
|
||||
void Notifier::Stop() { m_owner.Stop(); }
|
||||
|
||||
|
||||
@@ -45,10 +45,7 @@ Telemetry::Telemetry() {}
|
||||
|
||||
Telemetry::~Telemetry() {}
|
||||
|
||||
void Telemetry::Start() {
|
||||
auto thr = m_owner.GetThread();
|
||||
if (!thr) m_owner.Start(new Thread);
|
||||
}
|
||||
void Telemetry::Start() { m_owner.Start(); }
|
||||
|
||||
void Telemetry::Stop() { m_owner.Stop(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user