ros / class_loader

ROS-independent library for dynamic class (i.e. plugin) introspection and loading from runtime libraries
http://www.ros.org/wiki/class_loader
35 stars 95 forks source link

Memory leak: meta objects not destroyed #131

Open martiniil opened 4 years ago

martiniil commented 4 years ago

Using the ClassLoader (version 0.4.1) via pluginlib as recommended, we could detect some memory leaks. My guess is that metaobjects are not destroyed after they have been inserted into the "graveyard". Or did I miss something here?

Could be related: https://github.com/ros/pluginlib/issues/126

See the log below. It would be nice to get another opinion.

Excerpt of log.txt:

Direct leak of 160 byte(s) in 1 object(s) allocated from:
    #0 0x7f82ba691458 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0458)
    #1 0x7f82a3c28f4e in void class_loader::impl::registerPlugin<prbt_manipulator::IKFastKinematicsPlugin, kinematics::KinematicsBase>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /opt/ros/melodic/include/class_loader/class_loader_core.hpp:205
    #2 0x7f82a3b12d20 in ProxyExec0 /home/rosuser/catkin_ws/src/pilz_robots/prbt_ikfast_manipulator_plugin/src/prbt_manipulator_ikfast_moveit_plugin.cpp:1401
    #3 0x7f82a3b130f3 in __static_initialization_and_destruction_0 /home/rosuser/catkin_ws/src/pilz_robots/prbt_ikfast_manipulator_plugin/src/prbt_manipulator_ikfast_moveit_plugin.cpp:1401
    #4 0x7f82a3b1310e in _GLOBAL__sub_I_prbt_manipulator_ikfast_moveit_plugin.cpp /home/rosuser/catkin_ws/src/pilz_robots/prbt_ikfast_manipulator_plugin/src/prbt_manipulator_ikfast_moveit_plugin.cpp:1401
    #5 0x7f82bb57c732  (/lib64/ld-linux-x86-64.so.2+0x10732)

Indirect leak of 79 byte(s) in 1 object(s) allocated from:
    #0 0x7f82ba691458 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0458)
    #1 0x7f82b8795bc6 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0x124bc6)

Indirect leak of 68 byte(s) in 2 object(s) allocated from:
    #0 0x7f82ba691458 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0458)
    #1 0x7f82b9e6db6c  (/opt/ros/melodic/lib/libclass_loader.so+0x17b6c)

Indirect leak of 31 byte(s) in 1 object(s) allocated from:
    #0 0x7f82ba691458 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0458)
    #1 0x7f82ba36c3e2 in void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>(char const*, char const*, std::forward_iterator_tag) /usr/include/c++/7/bits/basic_string.tcc:219
    #2 0x7f82a3c3f1e7 in class_loader::impl::AbstractMetaObject<kinematics::KinematicsBase>::AbstractMetaObject(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /opt/ros/melodic/include/class_loader/meta_object.hpp:155
    #3 0x7f82a3c32f64 in class_loader::impl::MetaObject<prbt_manipulator::IKFastKinematicsPlugin, kinematics::KinematicsBase>::MetaObject(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /opt/ros/melodic/include/class_loader/meta_object.hpp:186
    #4 0x7f82a3c28f6a in void class_loader::impl::registerPlugin<prbt_manipulator::IKFastKinematicsPlugin, kinematics::KinematicsBase>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /opt/ros/melodic/include/class_loader/class_loader_core.hpp:205
    #5 0x7f82a3b12d20 in ProxyExec0 /home/rosuser/catkin_ws/src/pilz_robots/prbt_ikfast_manipulator_plugin/src/prbt_manipulator_ikfast_moveit_plugin.cpp:1401
    #6 0x7f82a3b130f3 in __static_initialization_and_destruction_0 /home/rosuser/catkin_ws/src/pilz_robots/prbt_ikfast_manipulator_plugin/src/prbt_manipulator_ikfast_moveit_plugin.cpp:1401
    #7 0x7f82a3b1310e in _GLOBAL__sub_I_prbt_manipulator_ikfast_moveit_plugin.cpp /home/rosuser/catkin_ws/src/pilz_robots/prbt_ikfast_manipulator_plugin/src/prbt_manipulator_ikfast_moveit_plugin.cpp:1401
    #8 0x7f82bb57c732  (/lib64/ld-linux-x86-64.so.2+0x10732)

Indirect leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x7f82ba691458 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xe0458)
    #1 0x7f82b9e6e383 in void std::vector<class_loader::ClassLoader*, std::allocator<class_loader::ClassLoader*> >::_M_realloc_insert<class_loader::ClassLoader* const&>(__gnu_cxx::__normal_iterator<class_loader::ClassLoader**, std::vector<class_loader::ClassLoader*, std::allocator<class_loader::ClassLoader*> > >, class_loader::ClassLoader* const&) (/opt/ros/melodic/lib/libclass_loader.so+0x18383)

SUMMARY: AddressSanitizer: 346 byte(s) leaked in 6 allocation(s).
agutenkunst commented 4 years ago

I created a minimal demo: https://github.com/agutenkunst/leak_demo_pkg

tylerjw commented 4 years ago

I second I've experienced this too. I get a flood of these when using moveit building with address sanitizer. I tried looking through the code to see if I can understand what I should be doing to fix this but I can't figure it out.

v4hn commented 3 years ago

According to these comments the whole problem boils down to the basic decision whether the library should

The library went with the former option and we are stuck with unfreeable memory as a result.