Skip to content

Commit a8c3f81

Browse files
authored
[command] Fix use-after-free in CommandScheduler (#3024)
1 parent 874e930 commit a8c3f81

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

cpp/frc2/command/CommandScheduler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ CommandScheduler::~CommandScheduler() {
8484
auto scheduler = frc::LiveWindow::GetInstance();
8585
scheduler->enabled = nullptr;
8686
scheduler->disabled = nullptr;
87+
88+
std::unique_ptr<Impl>().swap(m_impl);
8789
}
8890

8991
CommandScheduler& CommandScheduler::GetInstance() {
@@ -312,6 +314,10 @@ Command* CommandScheduler::GetDefaultCommand(const Subsystem* subsystem) const {
312314
}
313315

314316
void CommandScheduler::Cancel(Command* command) {
317+
if (!m_impl) {
318+
return;
319+
}
320+
315321
if (m_impl->inRunLoop) {
316322
m_impl->toCancel.emplace_back(command);
317323
return;

0 commit comments

Comments
 (0)