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

make sanitizer happy #205

Merged
merged 5 commits into from
Jan 16, 2023

Conversation

iuhilnehc-ynos
Copy link

@iuhilnehc-ynos iuhilnehc-ynos commented Oct 24, 2022

related to #201 (comment)

The CI logs will be expired in the future and might no longer be available, so I copy the log as follows,

MultiLibraryClassLoader memory leak

    ==6769==ERROR: LeakSanitizer: detected memory leaks
    
    Direct leak of 144 byte(s) in 1 object(s) allocated from:
        #0 0x7efc617811c7 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:99
        #1 0x7efc616bac16 in class_loader::MultiLibraryClassLoader::loadLibrary(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /root/target_ws/src/class_loader/src/multi_library_class_loader.cpp:96
        #2 0x56419df31a12 in MultiClassLoaderTest_noWarningOnLazyLoad_Test::TestBody() /root/target_ws/src/class_loader/test/utest.cpp:380
        #3 0x56419df88576 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2433
        #4 0x56419df8129e in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2469
        #5 0x56419df5b755 in testing::Test::Run() /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2508
        #6 0x56419df5c19a in testing::TestInfo::Run() /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2684
        #7 0x56419df5c8fb in testing::TestSuite::Run() /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2816
        #8 0x56419df68f10 in testing::internal::UnitTestImpl::RunAllTests() /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:5338
        #9 0x56419df89a68 in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2433
        #10 0x56419df824b2 in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2469
        #11 0x56419df676f2 in testing::UnitTest::Run() /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:4925
        #12 0x56419df3871f in RUN_ALL_TESTS() (/root/target_ws/build/class_loader/test/class_loader_utest+0x3271f)
        #13 0x56419df33fe6 in main /root/target_ws/src/class_loader/test/utest.cpp:448
        #14 0x7efc6110fd8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)
    
    Direct leak of 144 byte(s) in 1 object(s) allocated from:
        #0 0x7efc617811c7 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:99
        #1 0x7efc616bac16 in class_loader::MultiLibraryClassLoader::loadLibrary(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /root/target_ws/src/class_loader/src/multi_library_class_loader.cpp:96
        #2 0x56419df31a2b in MultiClassLoaderTest_noWarningOnLazyLoad_Test::TestBody() /root/target_ws/src/class_loader/test/utest.cpp:381
        #3 0x56419df88576 in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2433
        #4 0x56419df8129e in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2469
        #5 0x56419df5b755 in testing::Test::Run() /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2508
        #6 0x56419df5c19a in testing::TestInfo::Run() /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2684
        #7 0x56419df5c8fb in testing::TestSuite::Run() /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2816
        #8 0x56419df68f10 in testing::internal::UnitTestImpl::RunAllTests() /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:5338
        #9 0x56419df89a68 in bool testing::internal::HandleSehExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2433
        #10 0x56419df824b2 in bool testing::internal::HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool>(testing::internal::UnitTestImpl*, bool (testing::internal::UnitTestImpl::*)(), char const*) /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2469
        #11 0x56419df676f2 in testing::UnitTest::Run() /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:4925
        #12 0x56419df3871f in RUN_ALL_TESTS() (/root/target_ws/build/class_loader/test/class_loader_utest+0x3271f)
        #13 0x56419df33fe6 in main /root/target_ws/src/class_loader/test/utest.cpp:448
        #14 0x7efc6110fd8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f)
    
    Indirect leak of 64 byte(s) in 2 object(s) allocated from:
        #0 0x7efc617811c7 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:99
        #1 0x7efc61563ad9 in void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag) (/lib/x86_64-linux-gnu/libstdc++.so.6+0x14ead9)
    
    SUMMARY: AddressSanitizer: 352 byte(s) leaked in 4 allocation(s).

potential dead lock

    WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock) (pid=7271)
      Cycle in lock order graph: M98 (0x7b24000001e8) => M99 (0x7b2400000218) => M98
    
      Mutex M99 acquired here while holding mutex M98 in main thread:
        #0 pthread_mutex_lock ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:4240 (libtsan.so.0+0x53908)
        #1 __gthread_mutex_lock(pthread_mutex_t*) <null> (class_loader_unique_ptr_test+0x1d1ff)
        #2 __gthread_recursive_mutex_lock(pthread_mutex_t*) <null> (class_loader_unique_ptr_test+0x1d283)
        #3 std::recursive_mutex::lock() <null> (class_loader_unique_ptr_test+0x1d852)
        #4 class_loader::ClassLoader::unloadLibraryInternal(bool) /root/target_ws/src/class_loader/src/class_loader.cpp:122 (libclass_loader.so+0x37513)
        #5 void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2433 (class_loader_unique_ptr_test+0x64238)
        #6 main /root/target_ws/src/class_loader/test/unique_ptr_test.cpp:295 (class_loader_unique_ptr_test+0x1baf8)
    
        Hint: use TSAN_OPTIONS=second_deadlock_stack=1 to get more informative warning message
    
      Mutex M98 acquired here while holding mutex M99 in main thread:
        #0 pthread_mutex_lock ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:4240 (libtsan.so.0+0x53908)
        #1 __gthread_mutex_lock(pthread_mutex_t*) <null> (class_loader_unique_ptr_test+0x1d1ff)
        #2 __gthread_recursive_mutex_lock(pthread_mutex_t*) <null> (class_loader_unique_ptr_test+0x1d283)
        #3 std::recursive_mutex::lock() <null> (class_loader_unique_ptr_test+0x1d852)
        #4 std::lock_guard<std::recursive_mutex>::lock_guard(std::recursive_mutex&) <null> (class_loader_unique_ptr_test+0x22be4)
        #5 class_loader::ClassLoader::unloadLibraryInternal(bool) /root/target_ws/src/class_loader/src/class_loader.cpp:120 (libclass_loader.so+0x374fd)
        #6 void std::__invoke_impl<void, void (class_loader::ClassLoader::*&)(Base*), class_loader::ClassLoader*&, Base*>(std::__invoke_memfun_deref, void (class_loader::ClassLoader::*&)(Base*), class_loader::ClassLoader*&, Base*&&) <null> (class_loader_unique_ptr_test+0x2b939)
        #7 std::__invoke_result<void (class_loader::ClassLoader::*&)(Base*), class_loader::ClassLoader*&, Base*>::type std::__invoke<void (class_loader::ClassLoader::*&)(Base*), class_loader::ClassLoader*&, Base*>(void (class_loader::ClassLoader::*&)(Base*), class_loader::ClassLoader*&, Base*&&) <null> (class_loader_unique_ptr_test+0x2ad29)
        #8 void std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)>::__call<void, Base*&&, 0ul, 1ul>(std::tuple<Base*&&>&&, std::_Index_tuple<0ul, 1ul>) <null> (class_loader_unique_ptr_test+0x29efd)
        #9 void std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)>::operator()<Base*, void>(Base*&&) <null> (class_loader_unique_ptr_test+0x286fe)
        #10 void std::__invoke_impl<void, std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)>&, Base*>(std::__invoke_other, std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)>&, Base*&&) <null> (class_loader_unique_ptr_test+0x26557)
        #11 std::enable_if<std::__and_<std::is_void<void>, std::__is_invocable<std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)>&, Base*> >::value, void>::type std::__invoke_r<void, std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)>&, Base*>(std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)>&, Base*&&) <null> (class_loader_unique_ptr_test+0x24783)
        #12 std::_Function_handler<void (Base*), std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)> >::_M_invoke(std::_Any_data const&, Base*&&) <null> (class_loader_unique_ptr_test+0x22def)
        #13 std::function<void (Base*)>::operator()(Base*) const <null> (class_loader_unique_ptr_test+0x2118c)
        #14 std::unique_ptr<Base, std::function<void (Base*)> >::~unique_ptr() <null> (class_loader_unique_ptr_test+0x1efe8)
        #15 MultiClassLoaderUniquePtrTest_noWarningOnLazyLoad_Test::TestBody() /root/target_ws/src/class_loader/test/unique_ptr_test.cpp:284 (class_loader_unique_ptr_test+0x1b76e)
        #16 void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2433 (class_loader_unique_ptr_test+0x64238)
        #17 main /root/target_ws/src/class_loader/test/unique_ptr_test.cpp:295 (class_loader_unique_ptr_test+0x1baf8)
    
    SUMMARY: ThreadSanitizer: lock-order-inversion (potential deadlock) (/root/target_ws/build/class_loader/test/class_loader_unique_ptr_test+0x1d1ff) in __gthread_mutex_lock(pthread_mutex_t*)
    ==================
    ==================
    WARNING: ThreadSanitizer: lock-order-inversion (potential deadlock) (pid=7271)
      Cycle in lock order graph: M96 (0x7b24000000c8) => M97 (0x7b24000000f8) => M96
    
      Mutex M97 acquired here while holding mutex M96 in main thread:
        #0 pthread_mutex_lock ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:4240 (libtsan.so.0+0x53908)
        #1 __gthread_mutex_lock(pthread_mutex_t*) <null> (class_loader_unique_ptr_test+0x1d1ff)
        #2 __gthread_recursive_mutex_lock(pthread_mutex_t*) <null> (class_loader_unique_ptr_test+0x1d283)
        #3 std::recursive_mutex::lock() <null> (class_loader_unique_ptr_test+0x1d852)
        #4 class_loader::ClassLoader::unloadLibraryInternal(bool) /root/target_ws/src/class_loader/src/class_loader.cpp:122 (libclass_loader.so+0x37513)
        #5 void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2433 (class_loader_unique_ptr_test+0x64238)
        #6 main /root/target_ws/src/class_loader/test/unique_ptr_test.cpp:295 (class_loader_unique_ptr_test+0x1baf8)
    
        Hint: use TSAN_OPTIONS=second_deadlock_stack=1 to get more informative warning message
    
      Mutex M96 acquired here while holding mutex M97 in main thread:
        #0 pthread_mutex_lock ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:4240 (libtsan.so.0+0x53908)
        #1 __gthread_mutex_lock(pthread_mutex_t*) <null> (class_loader_unique_ptr_test+0x1d1ff)
        #2 __gthread_recursive_mutex_lock(pthread_mutex_t*) <null> (class_loader_unique_ptr_test+0x1d283)
        #3 std::recursive_mutex::lock() <null> (class_loader_unique_ptr_test+0x1d852)
        #4 std::lock_guard<std::recursive_mutex>::lock_guard(std::recursive_mutex&) <null> (class_loader_unique_ptr_test+0x22be4)
        #5 class_loader::ClassLoader::unloadLibraryInternal(bool) /root/target_ws/src/class_loader/src/class_loader.cpp:120 (libclass_loader.so+0x374fd)
        #6 void std::__invoke_impl<void, void (class_loader::ClassLoader::*&)(Base*), class_loader::ClassLoader*&, Base*>(std::__invoke_memfun_deref, void (class_loader::ClassLoader::*&)(Base*), class_loader::ClassLoader*&, Base*&&) <null> (class_loader_unique_ptr_test+0x2b939)
        #7 std::__invoke_result<void (class_loader::ClassLoader::*&)(Base*), class_loader::ClassLoader*&, Base*>::type std::__invoke<void (class_loader::ClassLoader::*&)(Base*), class_loader::ClassLoader*&, Base*>(void (class_loader::ClassLoader::*&)(Base*), class_loader::ClassLoader*&, Base*&&) <null> (class_loader_unique_ptr_test+0x2ad29)
        #8 void std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)>::__call<void, Base*&&, 0ul, 1ul>(std::tuple<Base*&&>&&, std::_Index_tuple<0ul, 1ul>) <null> (class_loader_unique_ptr_test+0x29efd)
        #9 void std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)>::operator()<Base*, void>(Base*&&) <null> (class_loader_unique_ptr_test+0x286fe)
        #10 void std::__invoke_impl<void, std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)>&, Base*>(std::__invoke_other, std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)>&, Base*&&) <null> (class_loader_unique_ptr_test+0x26557)
        #11 std::enable_if<std::__and_<std::is_void<void>, std::__is_invocable<std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)>&, Base*> >::value, void>::type std::__invoke_r<void, std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)>&, Base*>(std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)>&, Base*&&) <null> (class_loader_unique_ptr_test+0x24783)
        #12 std::_Function_handler<void (Base*), std::_Bind<void (class_loader::ClassLoader::*(class_loader::ClassLoader*, std::_Placeholder<1>))(Base*)> >::_M_invoke(std::_Any_data const&, Base*&&) <null> (class_loader_unique_ptr_test+0x22def)
        #13 std::function<void (Base*)>::operator()(Base*) const <null> (class_loader_unique_ptr_test+0x2118c)
        #14 std::unique_ptr<Base, std::function<void (Base*)> >::~unique_ptr() <null> (class_loader_unique_ptr_test+0x1efe8)
        #15 MultiClassLoaderUniquePtrTest_noWarningOnLazyLoad_Test::TestBody() /root/target_ws/src/class_loader/test/unique_ptr_test.cpp:284 (class_loader_unique_ptr_test+0x1b78c)
        #16 void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /opt/ros/rolling/src/gtest_vendor/./src/gtest.cc:2433 (class_loader_unique_ptr_test+0x64238)
        #17 main /root/target_ws/src/class_loader/test/unique_ptr_test.cpp:295 (class_loader_unique_ptr_test+0x1baf8)
    
    SUMMARY: ThreadSanitizer: lock-order-inversion (potential deadlock)

Signed-off-by: Chen Lihui lihui.chen@sony.com

@iuhilnehc-ynos
Copy link
Author

iuhilnehc-ynos commented Oct 24, 2022

@iuhilnehc-ynos iuhilnehc-ynos changed the title fix memory leak for MultiLibraryClassLoader make thread sanitizer happy Oct 24, 2022
@iuhilnehc-ynos iuhilnehc-ynos changed the title make thread sanitizer happy make sanitizer happy Oct 24, 2022
@iuhilnehc-ynos
Copy link
Author

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@iuhilnehc-ynos iuhilnehc-ynos marked this pull request as draft October 26, 2022 05:08
@iuhilnehc-ynos iuhilnehc-ynos force-pushed the topic_fix_MultiLibraryClassLoader branch 2 times, most recently from 9df9064 to f308370 Compare October 26, 2022 08:54
@iuhilnehc-ynos
Copy link
Author

retry CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@iuhilnehc-ynos iuhilnehc-ynos force-pushed the topic_fix_MultiLibraryClassLoader branch 2 times, most recently from 144c479 to 61423ab Compare October 27, 2022 09:33
@iuhilnehc-ynos
Copy link
Author

iuhilnehc-ynos commented Oct 27, 2022

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

retry CI:

  • Windows Build Status

Chen Lihui added 5 commits November 7, 2022 10:57
Signed-off-by: Chen Lihui <lihui.chen@sony.com>
Signed-off-by: Chen Lihui <lihui.chen@sony.com>
…ss_loaders_`

Signed-off-by: Chen Lihui <lihui.chen@sony.com>
… times

allow ClassLoader to unloadlibrary multiple times without throwing exception

Signed-off-by: Chen Lihui <lihui.chen@sony.com>
Signed-off-by: Chen Lihui <lihui.chen@sony.com>
@iuhilnehc-ynos iuhilnehc-ynos force-pushed the topic_fix_MultiLibraryClassLoader branch from 61423ab to 1d09914 Compare November 7, 2022 02:58
@fujitatomoya
Copy link

@iuhilnehc-ynos is this ready to review?

@iuhilnehc-ynos iuhilnehc-ynos marked this pull request as ready for review December 8, 2022 02:08
@gbiggs
Copy link
Contributor

gbiggs commented Dec 21, 2022

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

Copy link

@fujitatomoya fujitatomoya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@fujitatomoya
Copy link

@gbiggs can you merge this, we do not have permission on this repo.

@gbiggs
Copy link
Contributor

gbiggs commented Jan 16, 2023

Sure! Thanks for checking.

@gbiggs gbiggs merged commit 570cb1a into ros:rolling Jan 16, 2023
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

Successfully merging this pull request may close these issues.

3 participants