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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tools/rosbag_storage/include/rosbag/bag_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class BagPlayer
private:
ros::Time real_time(const ros::Time &msg_time);

std::map<std::string, BagCallback *> cbs_;
std::map<std::string, boost::shared_ptr<BagCallback> > cbs_;
ros::Time bag_start_;
ros::Time bag_end_;
ros::Time last_message_time_;
Expand All @@ -127,7 +127,7 @@ class BagPlayer
template<class T>
void BagPlayer::register_callback(const std::string &topic,
typename BagCallbackT<T>::Callback cb) {
cbs_[topic] = new BagCallbackT<T>(cb);
cbs_[topic] = boost::make_shared<BagCallbackT<T> >(cb);
}

}
Expand Down
3 changes: 1 addition & 2 deletions tools/rosbag_storage/src/bag_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ros::Time BagPlayer::real_time(const ros::Time &msg_time) {
void BagPlayer::start_play() {

std::vector<std::string> topics;
std::pair<std::string, BagCallback *> cb;
std::pair<std::string, boost::shared_ptr<BagCallback> > cb;
foreach(cb, cbs_)
topics.push_back(cb.first);

Expand All @@ -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.

cbs_.erase(topic);
}

Expand Down