orocos-toolchain / rtt

Orocos Real-Time Toolkit
http://www.orocos.org
Other
72 stars 79 forks source link

Fixed potential memory allocation problem in ConnectionManager #180

Closed meyerj closed 7 years ago

meyerj commented 7 years ago

The ConnectionManager is responsible for selecting the next channel to read if an InputPort has multiple connections, which are managed in a list of ChannelDescriptor instances. The ChannelDescriptor contains the ConnPolicy of the connection, which in turn contains a std::string element name_id. Copying ChannelDescriptor instances is therefore not real-time safe. Luckily it is not required and we can work with a pointer (or iterator) to the current channel.

It should be noted that most implementations of std::string usually do not reallocate once its internal buffer is big enough to hold all potential values (all name_ids of connected channels). So the risk that reassigning the std::string element in cur_channel is causing heap allocations in critical paths is quite minimal. See also http://info.prelert.com/blog/cpp-stdstring-implementations.

doudou commented 7 years ago

Looks good to me.