fix(px4_work_queue): don't touch a WorkItem after its Run() returns (#29278)

Modules that stop through ModuleBase::exit_and_cleanup() delete themselves
inside Run(), and since 9b62a1701d WorkQueue::Run() then clears
_run_in_progress in the freed object. ASAN aborts SITL on
`battery_simulator stop` and the stop of most other work queue modules.

Track the in-flight item in the WorkQueue instead, which lives until its
own Run() exits on the worker thread.

Assisted-by: Claude:claude-opus-5-5
This commit is contained in:
Jacob Dahl authored and GitHub committed 2026-10-19 12:37:19 +13:00
1 parent 50c4845d36
commit 8c5f4e0788
4 files changed
+15 -10

No files matched your search

@@ -205,12 +205,13 @@ void WorkQueue::Run()
// down. Without this, a Run() executing after Deinit has
// popped the item will call Schedule* on dead memory,
// corrupting the hrt callout queue.
work->_run_in_progress.store(true);
_running_item.store(work);
work_unlock(); // unlock work queue to run (item may requeue itself)
work->RunPreamble();
work->Run();
work->_run_in_progress.store(false);
// Note: after Run() we cannot access work anymore, as it might have been deleted
_running_item.store(nullptr);
work_lock(); // re-lock
}