Skip to content

Unmanaged instances throws out segfault after deleting plugin loader #218

Open
@CihatAltiparmak

Description

@CihatAltiparmak

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 :

https://gist.githubusercontent.com/DarkusAlphaHydranoid/71eef2bd0a092193653fc0dd895d409a/raw/80be7aee8969247e074ff9ddf09848f8c675a7e7/pluginlib_debug_build_with_Release.md

Scenario 2: compiled with colcon --mixin debug :

https://gist.githubusercontent.com/DarkusAlphaHydranoid/71eef2bd0a092193653fc0dd895d409a/raw/80be7aee8969247e074ff9ddf09848f8c675a7e7/pluginlib_debug_build_with_Debug.md

In accordance of above logs, seems in debug mode, although library is unloaded with below line

class_loader::impl::unloadLibrary(getLibraryPath(), this);

, 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.

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