aboutsummaryrefslogtreecommitdiff
path: root/engines/tony/mpal
diff options
context:
space:
mode:
authorPaul Gilbert2012-06-17 17:42:29 +1000
committerPaul Gilbert2012-06-17 17:42:29 +1000
commitd24fc8b5d895b595ec62ba1588d734392bc3a5e7 (patch)
tree80aa56c8a4fa75caa6b3fa88b86967d1f5bd8eea /engines/tony/mpal
parent9405f9eb4aed1d4c248e57ab4972b0132b2253f5 (diff)
downloadscummvm-rg350-d24fc8b5d895b595ec62ba1588d734392bc3a5e7.tar.gz
scummvm-rg350-d24fc8b5d895b595ec62ba1588d734392bc3a5e7.tar.bz2
scummvm-rg350-d24fc8b5d895b595ec62ba1588d734392bc3a5e7.zip
TONY: Fix memory leak in LocationPollThread
Diffstat (limited to 'engines/tony/mpal')
-rw-r--r--engines/tony/mpal/mpal.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/engines/tony/mpal/mpal.cpp b/engines/tony/mpal/mpal.cpp
index 72d8d3045c..07042ec077 100644
--- a/engines/tony/mpal/mpal.cpp
+++ b/engines/tony/mpal/mpal.cpp
@@ -824,12 +824,24 @@ void LocationPollThread(CORO_PARAM, const void *param) {
MYACTION *MyActions;
MYTHREAD *MyThreads;
+
+ ~CoroContextTag() {
+ // Free data blocks
+ if (MyThreads)
+ globalDestroy(MyThreads);
+ if (MyActions)
+ globalDestroy(MyActions);
+ }
CORO_END_CONTEXT(_ctx);
uint32 id = *((const uint32 *)param);
CORO_BEGIN_CODE(_ctx);
+ /* Initialise data pointers */
+ _ctx->MyActions = NULL;
+ _ctx->MyThreads = NULL;
+
/* To begin with, we need to request the item list from the location */
_ctx->il = mpalQueryItemList(GLOBALS._nPollingLocations[id]);
@@ -1045,12 +1057,6 @@ void LocationPollThread(CORO_PARAM, const void *param) {
// Set idle skip off
CORO_INVOKE_4(GLOBALS._lplpFunctions[201], 0, 0, 0, 0);
- /* We're finished */
- globalDestroy(_ctx->MyThreads);
- globalDestroy(_ctx->MyActions);
-
- CORO_KILL_SELF();
-
CORO_END_CODE;
}