From 4e35dbf528714d41faaec5e20504ed243cdded9e Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 26 Apr 2014 17:36:18 -0400 Subject: [PATCH] Fix ConsoleTrigger memory leak --- .../FeatureLib/pfConsole/pfAvatarConsoleCommands.cpp | 10 +++++----- Sources/Plasma/NucleusLib/pnMessage/plNotifyMsg.h | 5 ++++- .../Plasma/NucleusLib/pnModifier/plLogicModBase.cpp | 8 ++++---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfConsole/pfAvatarConsoleCommands.cpp b/Sources/Plasma/FeatureLib/pfConsole/pfAvatarConsoleCommands.cpp index 7f654085..23d1191a 100644 --- a/Sources/Plasma/FeatureLib/pfConsole/pfAvatarConsoleCommands.cpp +++ b/Sources/Plasma/FeatureLib/pfConsole/pfAvatarConsoleCommands.cpp @@ -368,11 +368,11 @@ PF_CONSOLE_CMD( Avatar_Multistage, Trigger, "string multiComp", "Triggers the na // Setup the event data in case this is a OneShot responder that needs it plKey playerKey = plAvatarMgr::GetInstance()->GetLocalAvatar()->GetKey(); - proPickedEventData *ed = new proPickedEventData; - ed->fPicker = playerKey; - ed->fPicked = key; // ??? - msg->AddEvent(ed); - + proPickedEventData ed; + ed.fPicker = playerKey; + ed.fPicked = key; // ??? + msg->AddEvent(&ed); + // Send it to the responder modifier msg->AddReceiver(key); plgDispatch::MsgSend(msg); diff --git a/Sources/Plasma/NucleusLib/pnMessage/plNotifyMsg.h b/Sources/Plasma/NucleusLib/pnMessage/plNotifyMsg.h index bf9b3512..2df26ad9 100644 --- a/Sources/Plasma/NucleusLib/pnMessage/plNotifyMsg.h +++ b/Sources/Plasma/NucleusLib/pnMessage/plNotifyMsg.h @@ -370,7 +370,10 @@ public: void SetType(notificationType type) { fType = type; } void SetState(float state) { fState = state; } - // event records for the notify message + /** + * Adds an arbitrary event to this notify message. + * \note This copies \a ed. + */ void AddEvent( proEventData* ed); void AddCollisionEvent( bool enter, const plKey &other, const plKey &self, bool onlyOneCollision=true ); void AddPickEvent( const plKey &other, const plKey& self, bool enabled, hsPoint3 hitPoint ); diff --git a/Sources/Plasma/NucleusLib/pnModifier/plLogicModBase.cpp b/Sources/Plasma/NucleusLib/pnModifier/plLogicModBase.cpp index dfee7765..4e5ae841 100644 --- a/Sources/Plasma/NucleusLib/pnModifier/plLogicModBase.cpp +++ b/Sources/Plasma/NucleusLib/pnModifier/plLogicModBase.cpp @@ -56,10 +56,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com void plLogicModBase::ConsoleTrigger(plKey playerKey) { // Setup the event data in case this is a OneShot responder that needs it - proPickedEventData *ed = new proPickedEventData; - ed->fPicker = playerKey; - ed->fPicked = nil; - fNotify->AddEvent(ed); + proPickedEventData ed; + ed.fPicker = playerKey; + ed.fPicked = nullptr; + fNotify->AddEvent(&ed); Trigger(false);