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:
@@ -294,8 +294,7 @@ class CallbackManager {
|
||||
protected:
|
||||
template <typename... Args>
|
||||
void DoStart(Args&&... args) {
|
||||
auto thr = m_owner.GetThread();
|
||||
if (!thr) m_owner.Start(new Thread(std::forward<Args>(args)...));
|
||||
m_owner.Start(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
|
||||
@@ -36,7 +36,7 @@ DsClient::DsClient(Dispatcher& dispatcher, wpi::Logger& logger)
|
||||
void DsClient::Start(unsigned int port) {
|
||||
auto thr = m_owner.GetThread();
|
||||
if (!thr)
|
||||
m_owner.Start(new Thread(m_dispatcher, m_logger, port));
|
||||
m_owner.Start(m_dispatcher, m_logger, port);
|
||||
else
|
||||
thr->m_port = port;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user