fix(mag_bias_estimator): return after cleanup in the stop path (#29792)

Run() calls exit_and_cleanup(desc) when should_exit() is set. That deletes the object, but Run() then continues to use _vehicle_status_sub, so the stop path reads freed memory.

Add the missing return. Reproduced with an ASan SITL build:

  ERROR: AddressSanitizer: heap-use-after-free ... READ of size 8
    #0 uORB::Subscription::subscribe()  platforms/common/uORB/Subscription.cpp:48
    #1 uORB::Subscription::updated()    platforms/common/uORB/Subscription.hpp:133
    #2 mag_bias_estimator::MagBiasEstimator::Run()  MagBiasEstimator.cpp:84

  freed by: MagBiasEstimator::~MagBiasEstimator()

Trigger: 'mag_bias_estimator start', then 'mag_bias_estimator stop'.

Assisted-by: deepseek

Signed-off-by: Summermu <23356722+Summermu@users.noreply.github.com>
This commit is contained in:
mumumu authored and GitHub committed 2026-11-17 14:01:59 -07:00
1 parent dc0cf5ec2e
commit cca69f2a5d
1 file changed
+1
@@ -81,6 +81,7 @@ void MagBiasEstimator::Run()
if (should_exit()) {
ScheduleClear();
exit_and_cleanup(desc);
return;
}
if (_vehicle_status_sub.updated()) {