Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak: meta objects not destroyed #131

Open
martiniil opened this issue Nov 29, 2019 · 3 comments
Open

Memory leak: meta objects not destroyed #131

martiniil opened this issue Nov 29, 2019 · 3 comments

Comments

@martiniil
Copy link

martiniil commented Nov 29, 2019

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: ros/pluginlib#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
Copy link

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

@tylerjw
Copy link

tylerjw commented Sep 15, 2020

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.

y-okumura-isp added a commit to y-okumura-isp/class_loader that referenced this issue Jan 20, 2021
@v4hn
Copy link
Contributor

v4hn commented May 27, 2021

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

  • support opening and closing libraries with plugins multiple times
    or
  • leak memory because there are no means to destroy the global factories correctly once the plugin libraries are dlclose()d.

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

v4hn added a commit to v4hn/moveit_task_constructor that referenced this issue May 27, 2021
to work around ros/class_loader#131
and have all code using the `CurrentState` stage sanitize correctly
(unless they use it through ClassLoader).
rhaschke pushed a commit to ubi-agni/moveit_task_constructor that referenced this issue May 27, 2021
to work around ros/class_loader#131
and have all code using the `CurrentState` stage sanitize correctly
(unless they use it through ClassLoader).
v4hn added a commit to v4hn/moveit_task_constructor that referenced this issue May 28, 2021
to work around ros/class_loader#131
and have all code using the `CurrentState` stage sanitize correctly
(unless they use it through ClassLoader).
rhaschke pushed a commit to moveit/moveit_task_constructor that referenced this issue May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants