diff options
author | Colin Snover | 2017-11-17 10:37:26 -0600 |
---|---|---|
committer | Eugene Sandulenko | 2017-11-18 22:35:12 +0100 |
commit | 8808817d56d37a66eb6a590715035076fcc14ade (patch) | |
tree | 03bd676d87e43d33038fdb7a72c5d6cbe9ec19bc /engines | |
parent | 2be96457b9132b62d220be072a1752e16946a123 (diff) | |
download | scummvm-rg350-8808817d56d37a66eb6a590715035076fcc14ade.tar.gz scummvm-rg350-8808817d56d37a66eb6a590715035076fcc14ade.tar.bz2 scummvm-rg350-8808817d56d37a66eb6a590715035076fcc14ade.zip |
FULLPIPE: Fix memory leaks of MessageQueues when clearing GlobalMessageQueueList
Diffstat (limited to 'engines')
-rw-r--r-- | engines/fullpipe/messages.cpp | 21 | ||||
-rw-r--r-- | engines/fullpipe/messages.h | 3 |
2 files changed, 19 insertions, 5 deletions
diff --git a/engines/fullpipe/messages.cpp b/engines/fullpipe/messages.cpp index d856d1beaf..bd8dff8009 100644 --- a/engines/fullpipe/messages.cpp +++ b/engines/fullpipe/messages.cpp @@ -263,7 +263,7 @@ MessageQueue::MessageQueue(MessageQueue *src, int parId, int field_38) { _id = g_fp->_globalMessageQueueList->compact(); _dataId = src->_dataId; - _flags = src->_flags; + _flags = src->_flags & ~kInGlobalQueue; _queueName = ""; g_fp->_globalMessageQueueList->addMessageQueue(this); @@ -319,7 +319,6 @@ bool MessageQueue::chain(StaticANIObject *ani) { if (checkGlobalExCommandList1() && checkGlobalExCommandList2()) { if (!(getFlags() & kInGlobalQueue)) { g_fp->_globalMessageQueueList->addMessageQueue(this); - _flags |= kInGlobalQueue; } if (ani) { ani->queueMessageQueue(this); @@ -656,9 +655,23 @@ int GlobalMessageQueueList::compact() { } void GlobalMessageQueueList::addMessageQueue(MessageQueue *msg) { - msg->setFlags(msg->getFlags() | kInGlobalQueue); + if ((msg->getFlags() & kInGlobalQueue) == 0) { + msg->setFlags(msg->getFlags() | kInGlobalQueue); + push_back(msg); + } else { + warning("Trying to add a MessageQueue already in the queue"); + } +} - push_back(msg); +void GlobalMessageQueueList::clear() { + for (iterator it = begin(); it != end(); ++it) { + // The MessageQueue destructor will try to remove itself from the global + // queue if it thinks it is in the global queue, which will break the + // iteration over the list + (*it)->_flags &= ~kInGlobalQueue; + delete *it; + } + Common::Array<MessageQueue *>::clear(); } void clearGlobalMessageQueueList() { diff --git a/engines/fullpipe/messages.h b/engines/fullpipe/messages.h index 91677a172d..71ec962c7c 100644 --- a/engines/fullpipe/messages.h +++ b/engines/fullpipe/messages.h @@ -163,13 +163,14 @@ class MessageQueue : public CObject { }; class GlobalMessageQueueList : public Common::Array<MessageQueue *> { - public: +public: MessageQueue *getMessageQueueById(int id); void deleteQueueById(int id); void removeQueueById(int id); void disableQueueById(int id); /** `msg` becomes owned by `this` */ void addMessageQueue(MessageQueue *msg); + void clear(); int compact(); }; |