-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix memory leak in talkaction #2145
Conversation
That was my mistake when changing it to list of objs instead of pointers.
Editing through github :x
src/talkaction.cpp
Outdated
@@ -61,7 +61,9 @@ Event* TalkActions::getEvent(const std::string& nodeName) | |||
|
|||
bool TalkActions::registerEvent(Event* event, const pugi::xml_node&) | |||
{ | |||
talkActions.push_front(*static_cast<TalkAction*>(event)); // event is guaranteed to be a TalkAction | |||
TalkAction* talkAction = static_cast<TalkAction*>(event); // event is guaranteed to be a TalkAction | |||
talkActions.push_front(*talkAction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::move(*talkaction)
might use less resources than copying here. Also I'd use an unique_ptr
for clean pointer handling.
auto talkaction = std::unique_ptr<Talkaction>(*event);
talkactions.push_front(std::move(*talkaction.get()));
src/talkaction.cpp
Outdated
@@ -61,7 +61,8 @@ Event* TalkActions::getEvent(const std::string& nodeName) | |||
|
|||
bool TalkActions::registerEvent(Event* event, const pugi::xml_node&) | |||
{ | |||
talkActions.push_front(*static_cast<TalkAction*>(event)); // event is guaranteed to be a TalkAction | |||
auto talkAction = std::unique_ptr<TalkAction>(static_cast<TalkAction*>(event)); // event is guaranteed to be a TalkAction | |||
talkActions.push_front(std::move(*talkAction.get())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed you can use *talkAction
, .get()
is redundant (source)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather use get to emphasize is not a normal pointer
Thanks! |
That was my mistake when changing it to list of objs instead of pointers.