[command] Fix use-after-free in CommandScheduler (#3024)

This commit is contained in:
Prateek Machiraju
2020-12-31 23:35:17 -05:00
committed by GitHub
parent 921a733911
commit 749c7adb13

View File

@@ -84,6 +84,8 @@ CommandScheduler::~CommandScheduler() {
auto scheduler = frc::LiveWindow::GetInstance();
scheduler->enabled = nullptr;
scheduler->disabled = nullptr;
std::unique_ptr<Impl>().swap(m_impl);
}
CommandScheduler& CommandScheduler::GetInstance() {
@@ -312,6 +314,10 @@ Command* CommandScheduler::GetDefaultCommand(const Subsystem* subsystem) const {
}
void CommandScheduler::Cancel(Command* command) {
if (!m_impl) {
return;
}
if (m_impl->inRunLoop) {
m_impl->toCancel.emplace_back(command);
return;