From 6f34660340421670c44d726249af3dd2f0be04fa Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Tue, 6 Oct 2015 15:47:48 +0200 Subject: [PATCH] QStateMachine: fix leak of delayed events. When a delayed event is queued, the state-machine is responsible for deleting it. Normal flow will ensure that: after the timer fires, the delayed event is handled normally, which includes deletion. However, when a timer cannot be set, the event was leaked. But more important: if there were unhandled (delayed) events when the state-machine was destoryed, the events were never deleted. Change-Id: I7d8a6b572765dc1551ddbdebb446aaa3258680c8 Reviewed-by: Simon Hausmann --- src/corelib/statemachine/qstatemachine.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/corelib/statemachine/qstatemachine.cpp b/src/corelib/statemachine/qstatemachine.cpp index 3ffe191093..31b079af0c 100644 --- a/src/corelib/statemachine/qstatemachine.cpp +++ b/src/corelib/statemachine/qstatemachine.cpp @@ -406,6 +406,10 @@ QStateMachinePrivate::~QStateMachinePrivate() { qDeleteAll(internalEventQueue); qDeleteAll(externalEventQueue); + + for (QHash::const_iterator it = delayedEvents.begin(), eit = delayedEvents.end(); it != eit; ++it) { + delete it.value().event; + } } QState *QStateMachinePrivate::rootState() const @@ -1944,6 +1948,7 @@ void QStateMachinePrivate::_q_startDelayedEventTimer(int id, int delay) e.timerId = q->startTimer(delay); if (!e.timerId) { qWarning("QStateMachine::postDelayedEvent: failed to start timer (id=%d, delay=%d)", id, delay); + delete e.event; delayedEvents.erase(it); delayedEventIdFreeList.release(id); } else {