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

feat: associative_vector rework #41

Merged
merged 29 commits into from
Feb 23, 2024

Conversation

tearfur
Copy link
Contributor

@tearfur tearfur commented Feb 21, 2024

Fixes #34
Fixes #35
Fixes #37
Fixes #39
Fixes #40

To make sure the changes are easy to trace, I was going to split this into 3 PRs, because I am used to squash merging. But since it looks like this repo is using rebase merge, I figured I can just lump all changes in to 1 PR.

@alandefreitas
Copy link
Owner

To make sure the changes are easy to trace, I was going to split this into 3 PRs, because I am used to squash merging. But since it looks like this repo is using rebase merge, I figured I can just lump all changes in to 1 PR.

Yes. There is no need to split and keep track of multiple PRs. Especially when all changes are related somehow and there are no competing PRs messing with the same code.

@alandefreitas
Copy link
Owner

alandefreitas commented Feb 21, 2024

About conventional commits, you can use "test" instead of "feat" for whatever is only related to tests.

types other than fix: and feat: are allowed, for example @commitlint/config-conventional (based on the Angular convention) recommends build:, chore:, ci:, docs:, style:, refactor:, perf:, test:, and others.

These dicts/maps contain a more formal list of the commit types: https://github.com/alandefreitas/cpp-actions/blob/3507d049fa58363fd14aac8dfcf32732e54cc782/create-changelog/create-changelog.py#L87-L101 / https://github.com/alandefreitas/cpp-actions/blob/3507d049fa58363fd14aac8dfcf32732e54cc782/create-changelog/create-changelog.py#L862-L877

@tearfur
Copy link
Contributor Author

tearfur commented Feb 21, 2024

Right, I will reword my commit titles then.

@tearfur
Copy link
Contributor Author

tearfur commented Feb 21, 2024

Man, I have no idea what clang-12 is on about... How is this not a constant expression?

/home/runner/work/small/small/include/small/detail/container/associative_vector.hpp:105:31: error: constexpr variable 'is_comp_tr' must be initialized by a constant expression
        static auto constexpr is_comp_tr = is_transparent_v<Compare>;
                              ^            ~~~~~~~~~~~~~~~~~~~~~~~~~

Meanwhile on my local machine with clang-14, there is a completely different error... And it also does not make sense.

In file included from /path/to/small/test/unit/small_set.cpp:8:
In file included from /path/to/small/include/small/set.hpp:12:
/path/to/small/include/small/detail/container/associative_vector.hpp:913:51: error: lambda capture 'this' is not used [-Werror,-Wunused-lambda-capture]
            return std::count_if(begin(), end(), [this, &x](auto const &v) {
                                                  ^

@tearfur tearfur force-pushed the erase-multi branch 2 times, most recently from a7e1a99 to 185882f Compare February 21, 2024 14:36
@tearfur tearfur marked this pull request as ready for review February 21, 2024 15:07
@alandefreitas
Copy link
Owner

alandefreitas commented Feb 21, 2024

Man, I have no idea what clang-12 is on about... How is this not a constant expression?

It seems like you fixed it then. :)

I've been using these https://github.com/alandefreitas/cpp-actions in libraries I maintain now (for instance, matplotplusplus and boost.url) but never got the time to update this library. We included many workarounds to fix conflicts we found between clang and updates in the runner images. Maybe there's some problem related to that.

@tearfur
Copy link
Contributor Author

tearfur commented Feb 22, 2024

It seems like you fixed it then. :)

Err, if you can call "updating clang to a newer version that doesn't show this warning" fixing it, then yes. :)

Anyways, ready for review now.
Edit: Goddamn it Microsoft.

@tearfur
Copy link
Contributor Author

tearfur commented Feb 22, 2024

THERE we go.

@tearfur
Copy link
Contributor Author

tearfur commented Feb 22, 2024

OK... I just tried the reworked small::map with std::shared_ptr as mapped_type in Transmission, now I am consistently getting shared_ptrs that deference deallocated memory... Oh boy

fsanitize output
=================================================================
==808017==ERROR: AddressSanitizer: heap-use-after-free on address 0x508000175a30 at pc 0x000000ec2974 bp 0x7f8c247f7400 sp 0x7f8c247f73f8
READ of size 1 at 0x508000175a30 thread T1
    #0 0xec2973 in int tr_compare_3way<tr_address_type>(tr_address_type const&, tr_address_type const&) /path/to/Transmission/libtransmission/../libtransmission/utils.h:165:16
    #1 0xebda39 in tr_address::compare(tr_address const&) const /path/to/Transmission/libtransmission/net.cc:559:26
    #2 0xde00da in tr_address::operator<(tr_address const&) const /path/to/Transmission/libtransmission/../libtransmission/net.h:220:22
    #3 0x10a9892 in int tr_compare_3way<tr_address>(tr_address const&, tr_address const&) /path/to/Transmission/libtransmission/../libtransmission/utils.h:165:14
    #4 0x10a970d in tr_socket_address::compare(tr_socket_address const&) const /path/to/Transmission/libtransmission/../libtransmission/net.h:313:30
    #5 0xfa103a in tr_socket_address::operator==(tr_socket_address const&) const /path/to/Transmission/libtransmission/../libtransmission/net.h:392:16
    #6 0xf4f355 in (anonymous namespace)::connect_helpers::get_peer_candidates(unsigned long, tr_torrents&, small::vector<std::pair<int, tr_socket_address>, 36ul, std::allocator<std::pair<int, tr_socket_address>>, std::integral_constant<bool, false>, unsigned long, std::ratio<3l, 2l>>&) /path/to/Transmission/libtransmission/peer-mgr.cc:2530:13
    #7 0xf4ab04 in tr_peerMgr::make_new_peer_connections() /path/to/Transmission/libtransmission/peer-mgr.cc:2611:9
    #8 0xf46d70 in tr_peerMgr::reconnect_pulse() /path/to/Transmission/libtransmission/peer-mgr.cc:2303:5
    #9 0xf4beb0 in tr_peerMgr::bandwidth_pulse() /path/to/Transmission/libtransmission/peer-mgr.cc:2343:5
    #10 0x1073172 in tr_peerMgr::tr_peerMgr(tr_session*, libtransmission::TimerMaker&, tr_torrents&, libtransmission::Blocklists&)::'lambda'()::operator()() const /path/to/Transmission/libtransmission/peer-mgr.cc:1084:59
    #11 0x1073103 in void std::__invoke_impl<void, tr_peerMgr::tr_peerMgr(tr_session*, libtransmission::TimerMaker&, tr_torrents&, libtransmission::Blocklists&)::'lambda'()&>(std::__invoke_other, tr_peerMgr::tr_peerMgr(tr_session*, libtransmission::TimerMaker&, tr_torrents&, libtransmission::Blocklists&)::'lambda'()&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/invoke.h:61:14
    #12 0x1073013 in std::enable_if<is_invocable_r_v<void, tr_peerMgr::tr_peerMgr(tr_session*, libtransmission::TimerMaker&, tr_torrents&, libtransmission::Blocklists&)::'lambda'()&>, void>::type std::__invoke_r<void, tr_peerMgr::tr_peerMgr(tr_session*, libtransmission::TimerMaker&, tr_torrents&, libtransmission::Blocklists&)::'lambda'()&>(tr_peerMgr::tr_peerMgr(tr_session*, libtransmission::TimerMaker&, tr_torrents&, libtransmission::Blocklists&)::'lambda'()&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/invoke.h:111:2
    #13 0x1072c72 in std::_Function_handler<void (), tr_peerMgr::tr_peerMgr(tr_session*, libtransmission::TimerMaker&, tr_torrents&, libtransmission::Blocklists&)::'lambda'()>::_M_invoke(std::_Any_data const&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/std_function.h:290:9
    #14 0x8757a9 in std::function<void ()>::operator()() const /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/std_function.h:591:9
    #15 0x8755ce in libtransmission::EvTimer::handleTimer() /path/to/Transmission/libtransmission/timer-ev.cc:151:9
    #16 0x87347d in libtransmission::EvTimer::onTimer(int, short, void*) /path/to/Transmission/libtransmission/timer-ev.cc:143:39
    #17 0x1681e9f in event_persist_closure /path/to/Transmission/third-party/libevent/event.c:1623:9
    #18 0x167c431 in event_process_active_single_queue /path/to/Transmission/third-party/libevent/event.c:1682:4
    #19 0x16565e2 in event_process_active /path/to/Transmission/third-party/libevent/event.c:1783:9
    #20 0x164e6ce in event_base_loop /path/to/Transmission/third-party/libevent/event.c:2006:12
    #21 0x135ee4e in tr_session_thread_impl::session_thread_func(event_base*) /path/to/Transmission/libtransmission/session-thread.cc:244:9
    #22 0x1365245 in void std::__invoke_impl<void, void (tr_session_thread_impl::*)(event_base*), tr_session_thread_impl*, event_base*>(std::__invoke_memfun_deref, void (tr_session_thread_impl::*&&)(event_base*), tr_session_thread_impl*&&, event_base*&&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/invoke.h:74:14
    #23 0x1364db1 in std::__invoke_result<void (tr_session_thread_impl::*)(event_base*), tr_session_thread_impl*, event_base*>::type std::__invoke<void (tr_session_thread_impl::*)(event_base*), tr_session_thread_impl*, event_base*>(void (tr_session_thread_impl::*&&)(event_base*), tr_session_thread_impl*&&, event_base*&&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/invoke.h:96:14
    #24 0x1364cd9 in void std::thread::_Invoker<std::tuple<void (tr_session_thread_impl::*)(event_base*), tr_session_thread_impl*, event_base*>>::_M_invoke<0ul, 1ul, 2ul>(std::_Index_tuple<0ul, 1ul, 2ul>) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/std_thread.h:292:13
    #25 0x1364b1b in std::thread::_Invoker<std::tuple<void (tr_session_thread_impl::*)(event_base*), tr_session_thread_impl*, event_base*>>::operator()() /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/std_thread.h:299:11
    #26 0x13642fe in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (tr_session_thread_impl::*)(event_base*), tr_session_thread_impl*, event_base*>>>::_M_run() /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/std_thread.h:244:13
    #27 0x7f8c296e31e2  (/lib64/libstdc++.so.6+0xe31e2) (BuildId: 43b5fe9c4fe0185772be4b57539be137c14a5c05)
    #28 0x4d9bae in asan_thread_start(void*) asan_interceptors.cpp.o
    #29 0x7f8c294ac896 in start_thread (/lib64/libc.so.6+0x8e896) (BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756)
    #30 0x7f8c2953380b in __GI___clone3 (/lib64/libc.so.6+0x11580b) (BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756)

0x508000175a30 is located 16 bytes inside of 88-byte region [0x508000175a20,0x508000175a78)
freed by thread T1 here:
    #0 0x51bcc1 in operator delete(void*) (/path/to/Transmission/build_fsanitize_small/daemon/transmission-daemon+0x51bcc1) (BuildId: 353246b98339d123afd5f4e9d4a6394c7e5d451e)
    #1 0x10c0941 in std::__new_allocator<std::_Sp_counted_ptr_inplace<tr_peer_info, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>>::deallocate(std::_Sp_counted_ptr_inplace<tr_peer_info, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>*, unsigned long) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/new_allocator.h:172:2
    #2 0x10bcfe3 in std::allocator_traits<std::allocator<std::_Sp_counted_ptr_inplace<tr_peer_info, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>>>::deallocate(std::allocator<std::_Sp_counted_ptr_inplace<tr_peer_info, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>>&, std::_Sp_counted_ptr_inplace<tr_peer_info, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>*, unsigned long) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/alloc_traits.h:517:13
    #3 0x10bcfe3 in std::__allocated_ptr<std::allocator<std::_Sp_counted_ptr_inplace<tr_peer_info, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>>>::~__allocated_ptr() /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/allocated_ptr.h:74:4
    #4 0x10bd960 in std::_Sp_counted_ptr_inplace<tr_peer_info, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_M_destroy() /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/shared_ptr_base.h:623:7
    #5 0x7ce497 in std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release() /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/shared_ptr_base.h:347:8
    #6 0x7cdf8f in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::~__shared_count() /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/shared_ptr_base.h:1071:11
    #7 0x109fbef in std::__shared_ptr<tr_peer_info, (__gnu_cxx::_Lock_policy)2>::~__shared_ptr() /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/shared_ptr_base.h:1524:31
    #8 0xf9dc9b in std::shared_ptr<tr_peer_info>::~shared_ptr() /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/shared_ptr.h:175:11
    #9 0x11736ac in tr_peerMsgs::~tr_peerMsgs() /path/to/Transmission/libtransmission/peer-msgs.cc:2100:1
    #10 0x1180bfc in (anonymous namespace)::tr_peerMsgsImpl::~tr_peerMsgsImpl() /path/to/Transmission/libtransmission/peer-msgs.cc:411:5
    #11 0x1180c6b in (anonymous namespace)::tr_peerMsgsImpl::~tr_peerMsgsImpl() /path/to/Transmission/libtransmission/peer-msgs.cc:403:5
    #12 0x1104519 in tr_swarm::remove_peer(tr_peerMsgs*) /path/to/Transmission/libtransmission/peer-mgr.cc:437:9
    #13 0xf6996c in (anonymous namespace)::disconnect_helpers::close_peer(tr_peerMsgs*) /path/to/Transmission/libtransmission/peer-mgr.cc:2165:18
    #14 0xf480f4 in (anonymous namespace)::disconnect_helpers::close_bad_peers(tr_swarm*, long, small::vector<tr_peerMsgs*, 512ul, std::allocator<tr_peerMsgs*>, std::integral_constant<bool, true>, unsigned long, std::ratio<3l, 2l>>&) /path/to/Transmission/libtransmission/peer-mgr.cc:2216:9
    #15 0xf46696 in tr_peerMgr::reconnect_pulse() /path/to/Transmission/libtransmission/peer-mgr.cc:2286:13
    #16 0xf4beb0 in tr_peerMgr::bandwidth_pulse() /path/to/Transmission/libtransmission/peer-mgr.cc:2343:5
    #17 0x1073172 in tr_peerMgr::tr_peerMgr(tr_session*, libtransmission::TimerMaker&, tr_torrents&, libtransmission::Blocklists&)::'lambda'()::operator()() const /path/to/Transmission/libtransmission/peer-mgr.cc:1084:59
    #18 0x1073103 in void std::__invoke_impl<void, tr_peerMgr::tr_peerMgr(tr_session*, libtransmission::TimerMaker&, tr_torrents&, libtransmission::Blocklists&)::'lambda'()&>(std::__invoke_other, tr_peerMgr::tr_peerMgr(tr_session*, libtransmission::TimerMaker&, tr_torrents&, libtransmission::Blocklists&)::'lambda'()&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/invoke.h:61:14
    #19 0x1073013 in std::enable_if<is_invocable_r_v<void, tr_peerMgr::tr_peerMgr(tr_session*, libtransmission::TimerMaker&, tr_torrents&, libtransmission::Blocklists&)::'lambda'()&>, void>::type std::__invoke_r<void, tr_peerMgr::tr_peerMgr(tr_session*, libtransmission::TimerMaker&, tr_torrents&, libtransmission::Blocklists&)::'lambda'()&>(tr_peerMgr::tr_peerMgr(tr_session*, libtransmission::TimerMaker&, tr_torrents&, libtransmission::Blocklists&)::'lambda'()&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/invoke.h:111:2
    #20 0x1072c72 in std::_Function_handler<void (), tr_peerMgr::tr_peerMgr(tr_session*, libtransmission::TimerMaker&, tr_torrents&, libtransmission::Blocklists&)::'lambda'()>::_M_invoke(std::_Any_data const&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/std_function.h:290:9
    #21 0x8757a9 in std::function<void ()>::operator()() const /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/std_function.h:591:9
    #22 0x8755ce in libtransmission::EvTimer::handleTimer() /path/to/Transmission/libtransmission/timer-ev.cc:151:9
    #23 0x87347d in libtransmission::EvTimer::onTimer(int, short, void*) /path/to/Transmission/libtransmission/timer-ev.cc:143:39
    #24 0x1681e9f in event_persist_closure /path/to/Transmission/third-party/libevent/event.c:1623:9
    #25 0x167c431 in event_process_active_single_queue /path/to/Transmission/third-party/libevent/event.c:1682:4
    #26 0x16565e2 in event_process_active /path/to/Transmission/third-party/libevent/event.c:1783:9
    #27 0x164e6ce in event_base_loop /path/to/Transmission/third-party/libevent/event.c:2006:12
    #28 0x135ee4e in tr_session_thread_impl::session_thread_func(event_base*) /path/to/Transmission/libtransmission/session-thread.cc:244:9
    #29 0x1365245 in void std::__invoke_impl<void, void (tr_session_thread_impl::*)(event_base*), tr_session_thread_impl*, event_base*>(std::__invoke_memfun_deref, void (tr_session_thread_impl::*&&)(event_base*), tr_session_thread_impl*&&, event_base*&&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/invoke.h:74:14
    #30 0x1364db1 in std::__invoke_result<void (tr_session_thread_impl::*)(event_base*), tr_session_thread_impl*, event_base*>::type std::__invoke<void (tr_session_thread_impl::*)(event_base*), tr_session_thread_impl*, event_base*>(void (tr_session_thread_impl::*&&)(event_base*), tr_session_thread_impl*&&, event_base*&&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/invoke.h:96:14

previously allocated by thread T1 here:
    #0 0x51b441 in operator new(unsigned long) (/path/to/Transmission/build_fsanitize_small/daemon/transmission-daemon+0x51b441) (BuildId: 353246b98339d123afd5f4e9d4a6394c7e5d451e)
    #1 0x10bd198 in std::__new_allocator<std::_Sp_counted_ptr_inplace<tr_peer_info, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>>::allocate(unsigned long, void const*) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/new_allocator.h:151:27
    #2 0x10bc752 in std::allocator_traits<std::allocator<std::_Sp_counted_ptr_inplace<tr_peer_info, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>>>::allocate(std::allocator<std::_Sp_counted_ptr_inplace<tr_peer_info, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>>&, unsigned long) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/alloc_traits.h:482:20
    #3 0x10bc752 in std::__allocated_ptr<std::allocator<std::_Sp_counted_ptr_inplace<tr_peer_info, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>>> std::__allocate_guarded<std::allocator<std::_Sp_counted_ptr_inplace<tr_peer_info, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>>>(std::allocator<std::_Sp_counted_ptr_inplace<tr_peer_info, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>>&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/allocated_ptr.h:98:21
    #4 0x10bc18f in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<tr_peer_info, std::allocator<void>, tr_socket_address const&, unsigned char const&, tr_peer_from const&>(tr_peer_info*&, std::_Sp_alloc_shared_tag<std::allocator<void>>, tr_socket_address const&, unsigned char const&, tr_peer_from const&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/shared_ptr_base.h:969:19
    #5 0x10bbe00 in std::__shared_ptr<tr_peer_info, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<void>, tr_socket_address const&, unsigned char const&, tr_peer_from const&>(std::_Sp_alloc_shared_tag<std::allocator<void>>, tr_socket_address const&, unsigned char const&, tr_peer_from const&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/shared_ptr_base.h:1712:14
    #6 0x10bbabe in std::shared_ptr<tr_peer_info>::shared_ptr<std::allocator<void>, tr_socket_address const&, unsigned char const&, tr_peer_from const&>(std::_Sp_alloc_shared_tag<std::allocator<void>>, tr_socket_address const&, unsigned char const&, tr_peer_from const&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/shared_ptr.h:464:4
    #7 0x10a293d in std::shared_ptr<std::enable_if<!is_array<tr_peer_info>::value, tr_peer_info>::type> std::make_shared<tr_peer_info, tr_socket_address const&, unsigned char const&, tr_peer_from const&>(tr_socket_address const&, unsigned char const&, tr_peer_from const&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/shared_ptr.h:1009:14
    #8 0xf9d804 in tr_swarm::ensure_info_exists(tr_socket_address const&, unsigned char, tr_peer_from) /path/to/Transmission/libtransmission/peer-mgr.cc:504:58
    #9 0xf35737 in tr_peerMgrAddPex(tr_torrent*, tr_peer_from, tr_pex const*, unsigned long) /path/to/Transmission/libtransmission/peer-mgr.cc:1426:16
    #10 0x128a8a0 in tr_resume::(anonymous namespace)::addPeers(tr_torrent*, unsigned char const*, unsigned long) /path/to/Transmission/libtransmission/resume.cc:65:12
    #11 0x12817b1 in tr_resume::(anonymous namespace)::loadPeers(tr_variant*, tr_torrent*) /path/to/Transmission/libtransmission/resume.cc:76:34
    #12 0x127b236 in tr_resume::(anonymous namespace)::load_from_file(tr_torrent*, tr_torrent::ResumeHelper&, unsigned long) /path/to/Transmission/libtransmission/resume.cc:740:26
    #13 0x1277599 in tr_resume::load(tr_torrent*, tr_torrent::ResumeHelper&, unsigned long, tr_ctor const&) /path/to/Transmission/libtransmission/resume.cc:868:12
    #14 0x8e1ec8 in tr_torrent::init(tr_ctor const&) /path/to/Transmission/libtransmission/torrent.cc:962:18
    #15 0x8ebbc7 in tr_torrentNew(tr_ctor*, tr_torrent**) /path/to/Transmission/libtransmission/torrent.cc:1094:10
    #16 0x742998 in (anonymous namespace)::load_torrents_helpers::session_load_torrents(tr_session*, tr_ctor*, std::promise<unsigned long>*) /path/to/Transmission/libtransmission/session.cc:1446:56
    #17 0x83b7df in void std::__invoke_impl<void, void (*&)(tr_session*, tr_ctor*, std::promise<unsigned long>*), tr_session*&, tr_ctor*&, std::promise<unsigned long>*&>(std::__invoke_other, void (*&)(tr_session*, tr_ctor*, std::promise<unsigned long>*), tr_session*&, tr_ctor*&, std::promise<unsigned long>*&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/invoke.h:61:14
    #18 0x83b230 in std::__invoke_result<void (*&)(tr_session*, tr_ctor*, std::promise<unsigned long>*), tr_session*&, tr_ctor*&, std::promise<unsigned long>*&>::type std::__invoke<void (*&)(tr_session*, tr_ctor*, std::promise<unsigned long>*), tr_session*&, tr_ctor*&, std::promise<unsigned long>*&>(void (*&)(tr_session*, tr_ctor*, std::promise<unsigned long>*), tr_session*&, tr_ctor*&, std::promise<unsigned long>*&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/invoke.h:96:14
    #19 0x83b09c in void std::_Bind<void (* (tr_session*, tr_ctor*, std::promise<unsigned long>*))(tr_session*, tr_ctor*, std::promise<unsigned long>*)>::__call<void, 0ul, 1ul, 2ul>(std::tuple<>&&, std::_Index_tuple<0ul, 1ul, 2ul>) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/functional:506:11
    #20 0x83abb0 in void std::_Bind<void (* (tr_session*, tr_ctor*, std::promise<unsigned long>*))(tr_session*, tr_ctor*, std::promise<unsigned long>*)>::operator()<void>() /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/functional:591:17
    #21 0x83aa93 in void std::__invoke_impl<void, std::_Bind<void (* (tr_session*, tr_ctor*, std::promise<unsigned long>*))(tr_session*, tr_ctor*, std::promise<unsigned long>*)>&>(std::__invoke_other, std::_Bind<void (* (tr_session*, tr_ctor*, std::promise<unsigned long>*))(tr_session*, tr_ctor*, std::promise<unsigned long>*)>&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/invoke.h:61:14
    #22 0x83a983 in std::enable_if<is_invocable_r_v<void, std::_Bind<void (* (tr_session*, tr_ctor*, std::promise<unsigned long>*))(tr_session*, tr_ctor*, std::promise<unsigned long>*)>&>, void>::type std::__invoke_r<void, std::_Bind<void (* (tr_session*, tr_ctor*, std::promise<unsigned long>*))(tr_session*, tr_ctor*, std::promise<unsigned long>*)>&>(std::_Bind<void (* (tr_session*, tr_ctor*, std::promise<unsigned long>*))(tr_session*, tr_ctor*, std::promise<unsigned long>*)>&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/invoke.h:111:2
    #23 0x839ef2 in std::_Function_handler<void (), std::_Bind<void (* (tr_session*, tr_ctor*, std::promise<unsigned long>*))(tr_session*, tr_ctor*, std::promise<unsigned long>*)>>::_M_invoke(std::_Any_data const&) /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/std_function.h:290:9
    #24 0x8757a9 in std::function<void ()>::operator()() const /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/std_function.h:591:9
    #25 0x13622bd in tr_session_thread_impl::on_work_available() /path/to/Transmission/libtransmission/session-thread.cc:272:13
    #26 0x135e95d in tr_session_thread_impl::on_work_available_static(int, short, void*) /path/to/Transmission/libtransmission/session-thread.cc:257:54
    #27 0x167cb39 in event_process_active_single_queue /path/to/Transmission/third-party/libevent/event.c:1691:4
    #28 0x16565e2 in event_process_active /path/to/Transmission/third-party/libevent/event.c:1783:9
    #29 0x164e6ce in event_base_loop /path/to/Transmission/third-party/libevent/event.c:2006:12
    #30 0x135ee4e in tr_session_thread_impl::session_thread_func(event_base*) /path/to/Transmission/libtransmission/session-thread.cc:244:9

Thread T1 created by T0 here:
    #0 0x4c30c1 in pthread_create (/path/to/Transmission/build_fsanitize_small/daemon/transmission-daemon+0x4c30c1) (BuildId: 353246b98339d123afd5f4e9d4a6394c7e5d451e)
    #1 0x7f8c296e32b8 in std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State>>, void (*)()) (/lib64/libstdc++.so.6+0xe32b8) (BuildId: 43b5fe9c4fe0185772be4b57539be137c14a5c05)
    #2 0x135e04d in tr_session_thread_impl::tr_session_thread_impl() /path/to/Transmission/libtransmission/session-thread.cc:155:19
    #3 0x135a147 in std::__detail::_MakeUniq<tr_session_thread_impl>::__single_object std::make_unique<tr_session_thread_impl>() /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/unique_ptr.h:1070:34
    #4 0x1358f8d in tr_session_thread::create() /path/to/Transmission/libtransmission/session-thread.cc:297:12
    #5 0x754664 in tr_session::tr_session(std::basic_string_view<char, std::char_traits<char>>, tr_variant const&) /path/to/Transmission/libtransmission/session.cc:2120:24
    #6 0x724c34 in tr_sessionInit(char const*, bool, tr_variant const&) /path/to/Transmission/libtransmission/session.cc:575:31
    #7 0x526d56 in tr_daemon::start(bool) /path/to/Transmission/daemon/daemon.cc:720:21
    #8 0x662df0 in tr_daemon::spawn(bool, int*, tr_error&) /path/to/Transmission/daemon/daemon-posix.cc:192:18
    #9 0x533367 in main /path/to/Transmission/daemon/daemon.cc:950:42
    #10 0x7f8c29446149 in __libc_start_call_main (/lib64/libc.so.6+0x28149) (BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756)
    #11 0x7f8c2944620a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2820a) (BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756)
    #12 0x43f2a4 in _start (/path/to/Transmission/build_fsanitize_small/daemon/transmission-daemon+0x43f2a4) (BuildId: 353246b98339d123afd5f4e9d4a6394c7e5d451e)

SUMMARY: AddressSanitizer: heap-use-after-free /path/to/Transmission/libtransmission/../libtransmission/utils.h:165:16 in int tr_compare_3way<tr_address_type>(tr_address_type const&, tr_address_type const&)
Shadow bytes around the buggy address:
  0x508000175780: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa
  0x508000175800: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa
  0x508000175880: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa
  0x508000175900: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa
  0x508000175980: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa
=>0x508000175a00: fa fa fa fa fd fd[fd]fd fd fd fd fd fd fd fd fa
  0x508000175a80: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa
  0x508000175b00: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa
  0x508000175b80: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa
  0x508000175c00: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa
  0x508000175c80: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==808017==ABORTING

Edit: It happens also with c6960c7, the issue seems to be with the underlying vector. See #42

@alandefreitas
Copy link
Owner

Err, if you can call "updating clang to a newer version that doesn't show this warning" fixing it, then yes. :)

😆

OK... I just tried the reworked small::map with std::shared_ptr as mapped_type in Transmission, now I am consistently getting shared_ptrs that deference deallocated memory... Oh boy

Oh boy indeed. 😆

I have to take the time to implement the complete cpp-actions here. The way CI is set up does not scale well.

So do you think this is good to go in the sense that it's better than before and whatever bugs we have were already there before?

if (it != end()) {
erase(it);
return 1;
return erase<decltype(k)>(k);
Copy link
Owner

Choose a reason for hiding this comment

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

Isn't decltype(k) always the same? const key_type&?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is.

Maybe this is just a matter of taste, I think this is better than writing out the type twice.

@alandefreitas
Copy link
Owner

Some files have changed enough that you add your name to the copyright :)

@tearfur
Copy link
Contributor Author

tearfur commented Feb 23, 2024

So do you think this is good to go in the sense that it's better than before and whatever bugs we have were already there before?

Yes, I think this PR is good to go. I'm not aware of any more bugs within associative_vector.hpp now. I tried to use std::vector as the underlying storage, and it is working fine so far.

Some files have changed enough that you add your name to the copyright :)

Done, is this format ok? be11365

@alandefreitas
Copy link
Owner

Done, is this format ok? be11365

I think it should be something like

// Copyright (c) 2024 Yat Ho ([email protected])
// Copyright (c) 2021 alandefreitas ([email protected])

@alandefreitas
Copy link
Owner

Yes, I think this PR is good to go. I'm not aware of any more bugs within associative_vector.hpp now. I tried to use std::vector as the underlying storage, and it is working fine so far.

Great. The way the commits are split also looks great.

@tearfur
Copy link
Contributor Author

tearfur commented Feb 23, 2024

I think it should be something like

Done 3c06653

@alandefreitas alandefreitas merged commit 7450d91 into alandefreitas:develop Feb 23, 2024
5 checks passed
@alandefreitas
Copy link
Owner

That's looking great. Thanks!

@tearfur tearfur deleted the erase-multi branch February 23, 2024 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment