From db4b02c5b17d2787744a7673680ff94806e32b2e Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 9 Sep 2021 09:53:39 +0100 Subject: [PATCH] Fix replacement of event queue background. This was discovered when EventQueue::background was called with a nullptr. It crashes the software as it tries to call into a nullptr. --- events/source/EventQueue.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/events/source/EventQueue.cpp b/events/source/EventQueue.cpp index 795704914b..b7c779f7bf 100644 --- a/events/source/EventQueue.cpp +++ b/events/source/EventQueue.cpp @@ -83,12 +83,18 @@ int EventQueue::time_left(int id) void EventQueue::background(Callback update) { + // Start by setting the background callback to nullptr + // as equeue_background calls the existing handler with a timeout + // of -1 to indicate to the callback that the tineout process is + // not further required. + // Updating _update before would prevent calling into the + // old callback as the callbacks share the same memory locations. + equeue_background(&_equeue, 0, 0); + _update = update; if (_update) { equeue_background(&_equeue, &Callback::thunk, &_update); - } else { - equeue_background(&_equeue, 0, 0); } }