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

Use boost::shared_ptr to fix memory leak in BagPlayer #1373

Merged
merged 1 commit into from
Apr 23, 2018

Conversation

efernandez
Copy link
Contributor

@efernandez efernandez commented Apr 22, 2018

This fixes two memory leaks in BagPlayer by changing the std::map of RAW pointers to BagCallback to smart pointers boost::shared_ptr<BagCallback>"

  1. On destruction, b/c the destructor doesn't delete the RAW pointers in the std::map.
  2. In register_callback is called with the same topic name more than once w/o calling unregister_callback for that topic name.

This should also work now if we call unregister_callback for a topic not previously registered. Before that would delete a null pointer.

with std::map of BagCallback, instead of RAW pointer.

This solves two memory leaks:
1. On destruction, b/c the destruction doesn't delete the RAW pointers
   in the std::map.
2. In register_callback is called with the same topic name more than
   once w/o calling unregister_callback for that topic name.
@efernandez
Copy link
Contributor Author

FYI @dirk-thomas

@@ -63,7 +63,6 @@ void BagPlayer::start_play() {
}

void BagPlayer::unregister_callback(const std::string &topic) {
delete cbs_[topic];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means it will now not be deleted until the whole object goes out of scope. Perhaps there should still be a cbs_.erase(topic) or something here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, that's in the next line. I didn't remove it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh lol, so I see.

@efernandez
Copy link
Contributor Author

Looks like the tests are currently broken b/c of something else, unrelated with this PR, right?

@mikepurvis
Copy link
Member

Yes, the debian stretch issue is being investigated in #1358; the other test is flakey.

@mikepurvis mikepurvis merged commit 2d1382a into ros:melodic-devel Apr 23, 2018
@efernandez efernandez deleted the fix_bag_player_memory_leak branch April 23, 2018 21:12
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.

2 participants