Description
Hi,
When the package used pluginlib
is compiled in Release
mode, it throws out segmentation fault so seems the instance of corresponding plugin base class tries to read forbidden address, which locates the relavant stuffs of destructor of shared lib that is unloaded right before deleting unmanaged instance. But this behaviours don't occur when corresponding package package is built either without any CMAKE_BUILD_TYPE(shortly colcon build
) or with Debug mode(shortly colcon build --mixin debug
)
Description
#include <pluginlib/class_loader.hpp>
#include <polygon_base/regular_polygon.hpp>
#include <iostream>
int main(int argc, char** argv)
{
// To avoid unused parameter warnings
(void) argc;
(void) argv;
std::shared_ptr<pluginlib::ClassLoader<polygon_base::RegularPolygon>> poly_loader
= std::make_shared<pluginlib::ClassLoader<polygon_base::RegularPolygon>>("polygon_base", "polygon_base::RegularPolygon");
std::unique_ptr<polygon_base::RegularPolygon> triangle
= std::unique_ptr<polygon_base::RegularPolygon>(poly_loader->createUnmanagedInstance("polygon_plugins::Triangle"));
poly_loader.reset();
return 0;
}
To trigger these behaviors, i have created example package which originated from ros2 plugin tutorials but with some modifications and conducted debugs.
Scenario 1: compiled with colcon --mixin release
:
Scenario 2: compiled with colcon --mixin debug
:
In accordance of above logs, seems in debug mode, although library is unloaded with below line
class_loader/src/class_loader.cpp
Line 136 in 464fd14
, it is not unloaded. But in release mode, above method immidiately unloads shared library.
How to reproduce
git clone https://github.com/DarkusAlphaHydranoid/ros2_examples_plugin_debug
cd ros2_examples_plugin_debug
docker build -t plugin_debug .
Then go ahead as you wish.
Additional
I have found this error while trying this PR. But in this case, even if it's not compiled with release, it throws out very similar segfault again.