mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-17 23:27:37 +00:00
LASTEXPRESS: Fix leak and corruption of event handlers function pointers
- Add better error handling - Properly delete previous event handlers when setting new ones or restoring from backup
This commit is contained in:
parent
434a2e66b1
commit
85bb5ef45e
@ -288,22 +288,34 @@ void LastExpressEngine::handleSoundTimer() {
|
||||
/// Event Handling
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
void LastExpressEngine::backupEventHandlers() {
|
||||
if (_eventMouseBackup != NULL || _eventTickBackup != NULL)
|
||||
error("[LastExpressEngine::backupEventHandlers] backup event handlers are already set");
|
||||
|
||||
_eventMouseBackup = _eventMouse;
|
||||
_eventTickBackup = _eventTick;
|
||||
}
|
||||
|
||||
void LastExpressEngine::restoreEventHandlers() {
|
||||
if (_eventMouseBackup == NULL || _eventTickBackup == NULL)
|
||||
error("LastExpressEngine::restoreEventHandlers: restore called before backing up the event handlers!");
|
||||
error("[LastExpressEngine::restoreEventHandlers] restore called before backing up the event handlers");
|
||||
|
||||
// Cleanup previous event handlers
|
||||
SAFE_DELETE(_eventMouse);
|
||||
SAFE_DELETE(_eventTick);
|
||||
|
||||
_eventMouse = _eventMouseBackup;
|
||||
_eventTick = _eventTickBackup;
|
||||
|
||||
_eventMouseBackup = NULL;
|
||||
_eventTickBackup = NULL;
|
||||
}
|
||||
|
||||
void LastExpressEngine::setEventHandlers(EventHandler::EventFunction *mouse, EventHandler::EventFunction *tick) {
|
||||
// Cleanup previous event handlers
|
||||
delete _eventMouse;
|
||||
delete _eventTick;
|
||||
if (_eventMouse != _eventMouseBackup)
|
||||
SAFE_DELETE(_eventMouse);
|
||||
|
||||
if (_eventTick != _eventTickBackup)
|
||||
SAFE_DELETE(_eventTick);
|
||||
|
||||
_eventMouse = mouse;
|
||||
_eventTick = tick;
|
||||
|
Loading…
Reference in New Issue
Block a user