From d24fc8b5d895b595ec62ba1588d734392bc3a5e7 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 17 Jun 2012 17:42:29 +1000 Subject: TONY: Fix memory leak in LocationPollThread --- engines/tony/mpal/mpal.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'engines/tony/mpal') 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; } -- cgit v1.2.3