This repository was archived by the owner on May 31, 2025. It is now read-only.
Use boost::shared_ptr to fix memory leak in BagPlayer#1373
Merged
mikepurvis merged 1 commit intoros:melodic-develfrom Apr 23, 2018
Merged
Use boost::shared_ptr to fix memory leak in BagPlayer#1373mikepurvis merged 1 commit intoros:melodic-develfrom
mikepurvis merged 1 commit intoros:melodic-develfrom
Conversation
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.
Contributor
Author
|
FYI @dirk-thomas |
mikepurvis
reviewed
Apr 23, 2018
| } | ||
|
|
||
| void BagPlayer::unregister_callback(const std::string &topic) { | ||
| delete cbs_[topic]; |
Member
There was a problem hiding this comment.
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?
Contributor
Author
There was a problem hiding this comment.
Of course, that's in the next line. I didn't remove it.
Contributor
Author
|
Looks like the tests are currently broken b/c of something else, unrelated with this PR, right? |
Member
|
Yes, the debian stretch issue is being investigated in #1358; the other test is flakey. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes two memory leaks in
BagPlayerby changing thestd::mapof RAW pointers toBagCallbackto smart pointersboost::shared_ptr<BagCallback>"deletethe RAW pointers in thestd::map.register_callbackis called with the sametopicname more than once w/o callingunregister_callbackfor that topic name.This should also work now if we call
unregister_callbackfor a topic not previously registered. Before that woulddeletea null pointer.