asio icon indicating copy to clipboard operation
asio copied to clipboard

alloc-dealloc-mismatch (at least on 1.19.2)

Open AmarOk1412 opened this issue 4 years ago • 2 comments

On GNU/Linux, with ASAN I see



==90523==ERROR: AddressSanitizer: alloc-dealloc-mismatch (operator new vs free) on 0x613000020100
    #0 0x7f7df2d99f19 in __interceptor_free /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:127
    #1 0x7f7df1916ef1 in asio::detail::scheduler::run(std::error_code&) [clone .isra.0] (/usr/local/lib/libring.so.0+0x353ef1)
    #2 0x7f7df19183f9 in std::thread::_State_impl<std::thread::_Invoker<std::tuple<jami::Manager::ManagerPimpl::ManagerPimpl(jami::Manager&)::{lambda()#1}> > >::_M_run() (/usr/local/lib/libring.so.0+0x3553f9)
    #3 0x7f7dedf133c3 in execute_native_thread_routine /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:82
    #4 0x7f7df1049258 in start_thread (/usr/lib/libpthread.so.0+0x9258)
    #5 0x7f7dedc135e2 in __GI___clone (/usr/lib/libc.so.6+0xfe5e2)

0x613000020100 is located 0 bytes inside of 321-byte region [0x613000020100,0x613000020241)
allocated by thread T5 here:
    #0 0x7f7df2d9bca1 in operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/asan/asan_new_delete.cpp:99
    #1 0x7f7df0d0fc47 in void* asio::detail::thread_info_base::allocate<asio::detail::thread_info_base::default_tag>(asio::detail::thread_info_base::default_tag, asio::detail::thread_info_base*, unsigned long, unsigned long) [clone .constprop.0] (/usr/local/lib/libopendht.so.2+0x5a2c47)

Thread T3 created by T0 here:
    #0 0x7f7df2d3bfa7 in __interceptor_pthread_create /build/gcc/src/gcc/libsanitizer/asan/asan_interceptors.cpp:216
    #1 0x7f7dedf136aa in std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu/bits/gthr-default.h:663
    #2 0x7ffc9dadb62f  ([stack]+0x1962f)

Thread T5 created by T0 here:
    #0 0x7f7df2d3bfa7 in __interceptor_pthread_create /build/gcc/src/gcc/libsanitizer/asan/asan_interceptors.cpp:216
    #1 0x7f7dedf136aa in std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu/bits/gthr-default.h:663
    #2 0x7ffc9dadaa0f  ([stack]+0x18a0f)

SUMMARY: AddressSanitize

We use asio-1-19-2 and build ./configure --without-boost

AmarOk1412 avatar Feb 18 '22 20:02 AmarOk1412

I'm finding mismatched new/free (CWE-401) via static analysis using v1.22.1

Files/lines where detected:

  • asio/impl/cancellation_signal.ipp
    • 32
    • 44
    • 67
    • 85
  • asio/detail/executor_op.hpp
    • 34

This doesn't look like the same files as above, but it seems related and I thought I put this here instead of opening a new issue

jharmer95 avatar Mar 17 '22 23:03 jharmer95

@AmarOk1412:

Your libring.so library is probably being compiled for c++17 or later (so that std::aligned_alloc is available, which is paired with std::free). On the other hand, libopendht.so is compiled for c++14 or earlier (std::aligned_alloc is not available, so operator new/delete are used).

@jharmer95:

In the absence of further details, I'd suggest these are spurious.

chriskohlhoff avatar Mar 18 '22 00:03 chriskohlhoff