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 <simon.hausmann@theqtcompany.com>
This commit is contained in:
parent
6951f0e4af
commit
6f34660340
@ -406,6 +406,10 @@ QStateMachinePrivate::~QStateMachinePrivate()
|
||||
{
|
||||
qDeleteAll(internalEventQueue);
|
||||
qDeleteAll(externalEventQueue);
|
||||
|
||||
for (QHash<int, DelayedEvent>::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 {
|
||||
|
Loading…
Reference in New Issue
Block a user