From 2d0d5c82d1e8f2618388e57f8591d7eafcdbeb72 Mon Sep 17 00:00:00 2001 From: Sune Vuorela Date: Tue, 24 May 2022 13:51:25 +0200 Subject: [PATCH] MOZ-0: Fix memleak It looks like we have a memory leak if the event queue is full. In that case, I haven't been able to find who should deallocate the queue event object, so we that should probably happen here. --- events/include/events/EventQueue.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/events/include/events/EventQueue.h b/events/include/events/EventQueue.h index 9aa644491f5..626b5b66a77 100644 --- a/events/include/events/EventQueue.h +++ b/events/include/events/EventQueue.h @@ -762,8 +762,10 @@ class EventQueue : private mbed::NonCopyable { F *e = new (p) F(std::move(f)); equeue_event_dtor(e, &EventQueue::function_dtor); int id = equeue_post(&_equeue, &EventQueue::function_call, e); - if (!id) + if (!id) { queue_full(QUEUE_FULL_CALL, sizeof(F)); + equeue_dealloc(&_equeue, p); + } return id; } @@ -842,8 +844,10 @@ class EventQueue : private mbed::NonCopyable { equeue_event_delay(e, ms.count()); equeue_event_dtor(e, &EventQueue::function_dtor); int id = equeue_post(&_equeue, &EventQueue::function_call, e); - if (!id) + if (!id) { queue_full(QUEUE_FULL_CALL_IN, sizeof(F)); + equeue_dealloc(&_equeue, p); + } return id; } @@ -1000,8 +1004,10 @@ class EventQueue : private mbed::NonCopyable { equeue_event_period(e, ms.count()); equeue_event_dtor(e, &EventQueue::function_dtor); int id = equeue_post(&_equeue, &EventQueue::function_call, e); - if (!id) + if (!id) { queue_full(QUEUE_FULL_CALL_EVERY, sizeof(F)); + equeue_dealloc(&_equeue, p); + } return id; }