Skip to content

Memory Leak in snapshotter::subscribe() #2

@arneboe

Description

@arneboe

This bug was already present and pointed out in the old PR (ros/ros_comm#1414).

As far as I can see it is still present in this version.

Copy&paste from old PR:
There is a memory leak in Snapshotter::subscribe.
You are binding topicCB using boost::bind with queue as additional parameter.
Therefore the subscriber holds a shared_ptr to the queue.
Storing the subscriber inside the queue (queue->setSubscriber(sub);) essentially makes the queue hold a shared_ptr to itself and thus it will never be deleted.
Never deleting the subscriber will in turn stop a whole bunch of ros internals from getting shutdown properly.

A possible fix (albeit not a very nice one) is.

Snapshotter::~Snapshotter()
{
    for (std::pair<const std::string, boost::shared_ptr<MessageQueue>>& buffer : buffers_) 
    {
      buffer.second->sub_->shutdown();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions