From f70b6dd6403d41560ca2abee33db1af3d2c0e073 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Mon, 1 Apr 2019 14:29:47 +0200 Subject: [PATCH] mission: fix double call of result callback We need to make sure we set the callback to nullptr while we have the lock. This way we make sure we only ever call the callback once and don't upset the API user. --- plugins/mission/mission_impl.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/mission/mission_impl.cpp b/plugins/mission/mission_impl.cpp index 30989d4670..b0bf98ebf3 100644 --- a/plugins/mission/mission_impl.cpp +++ b/plugins/mission/mission_impl.cpp @@ -140,6 +140,11 @@ void MissionImpl::process_mission_ack(const mavlink_message_t &message) { std::lock_guard lock(_mission_data.mutex); temp_callback = _mission_data.result_callback; + // For the odd case where mission_ack is processed twice in quick succession + // we need to make sure we only copy the callback once and only get nullptr + // for the subsequent case. Otherwise we might report a result twice and + // upset a caller. + _mission_data.result_callback = nullptr; } {