Skip to content
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

Merged
merged 5 commits into from
Feb 2, 2017
Merged

Fix memory leak in talkaction #2145

merged 5 commits into from
Feb 2, 2017

Conversation

Mkalo
Copy link
Contributor

@Mkalo Mkalo commented Feb 1, 2017

That was my mistake when changing it to list of objs instead of pointers.

That was my mistake when changing it to list of objs instead of pointers.
Editing through github :x
@@ -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);
Copy link
Member

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()));

@@ -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()));
Copy link
Member

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)

Copy link
Contributor

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

@ranisalt ranisalt merged commit 8abb529 into otland:master Feb 2, 2017
@ranisalt
Copy link
Member

ranisalt commented Feb 2, 2017

Thanks!

@Mkalo Mkalo deleted the patch-3 branch February 2, 2017 08:21
@WibbenZ WibbenZ added this to the 1.3 milestone Dec 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants