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

AddressSanitizer: new-delete-type-mismatch #2220

Open
fujitatomoya opened this issue Jun 20, 2023 · 9 comments
Open

AddressSanitizer: new-delete-type-mismatch #2220

fujitatomoya opened this issue Jun 20, 2023 · 9 comments
Labels
backlog bug Something isn't working

Comments

@fujitatomoya
Copy link
Collaborator

Bug report

Required Info:

  • Operating System:
    • Ubuntu 22.04
  • Installation type:
    • source build rolling
  • Version or commit hash:
  • DDS implementation:
    • Any
  • Client library (if applicable):
    • rclcpp

Steps to reproduce issue

colcon build --symlink-install --cmake-args -DCMAKE_CXX_FLAGS="-g  -fsanitize=address" -DCMAKE_C_FLAGS="-g -fsanitize=address"
source install/local_setup.bash
ros2 run demo_nodes_cpp talker
...

Expected behavior

No ASAN report generated.

Actual behavior

The following ASAN report generated.

AddressSanitizer: new-delete-type-mismatch
root@tomoyafujita:~/ros2_ws/colcon_ws# ros2 run demo_nodes_cpp talker
=================================================================
==726931==ERROR: AddressSanitizer: new-delete-type-mismatch on 0x60600006c0e0 in thread T0:
  object passed to delete has wrong type:
  size of the allocated type:   64 bytes;
  size of the deallocated type: 1 bytes.
    #0 0x7f7b840bd22f in operator delete(void*, unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:172
    #1 0x7f7b82772587 in rcutils_string_map_fini /root/ros2_ws/colcon_ws/src/ros2/rcutils/src/string_map.c:105
    #2 0x7f7b8354dfb0 in rcl_resolve_name /root/ros2_ws/colcon_ws/src/ros2/rcl/rcl/src/rcl/node_resolve_name.c:110
    #3 0x7f7b8354e751 in rcl_node_resolve_name /root/ros2_ws/colcon_ws/src/ros2/rcl/rcl/src/rcl/node_resolve_name.c:152
    #4 0x7f7b835483e5 in rcl_publisher_init /root/ros2_ws/colcon_ws/src/ros2/rcl/rcl/src/rcl/publisher.c:83
    #5 0x7f7b83c0bc16 in rclcpp::PublisherBase::PublisherBase(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rosidl_message_type_support_t const&, rcl_publisher_options_s const&, rclcpp::PublisherEventCallbacks const&, bool) /root/ros2_ws/colcon_ws/src/ros2/rclcpp/rclcpp/src/rclcpp/publisher_base.cpp:73
    #6 0x7f7b83a55937 in rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> >::Publisher(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&) /root/ros2_ws/colcon_ws/src/ros2/rclcpp/rclcpp/include/rclcpp/publisher.hpp:140
    #7 0x7f7b83a56e01 in void __gnu_cxx::new_allocator<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >::construct<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> >, rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&>(rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> >*, rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&) /usr/include/c++/11/ext/new_allocator.h:162
    #8 0x7f7b83a56e01 in void std::allocator_traits<std::allocator<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > > >::construct<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> >, rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&>(std::allocator<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >&, rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> >*, rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&) /usr/include/c++/11/bits/alloc_traits.h:516
    #9 0x7f7b83a56e01 in std::_Sp_counted_ptr_inplace<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> >, std::allocator<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&>(std::allocator<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >, rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&) /usr/include/c++/11/bits/shared_ptr_base.h:519
    #10 0x7f7b83a56e01 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> >, std::allocator<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >, rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&>(rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> >*&, std::_Sp_alloc_shared_tag<std::allocator<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > > >, rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&) /usr/include/c++/11/bits/shared_ptr_base.h:650
    #11 0x7f7b83a56e01 in std::__shared_ptr<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> >, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >, rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&>(std::_Sp_alloc_shared_tag<std::allocator<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > > >, rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&) /usr/include/c++/11/bits/shared_ptr_base.h:1342
    #12 0x7f7b83a56e01 in std::shared_ptr<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >::shared_ptr<std::allocator<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >, rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&>(std::_Sp_alloc_shared_tag<std::allocator<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > > >, rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&) /usr/include/c++/11/bits/shared_ptr.h:409
    #13 0x7f7b83a56e01 in std::shared_ptr<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > > std::allocate_shared<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> >, std::allocator<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >, rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&>(std::allocator<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > > const&, rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&) /usr/include/c++/11/bits/shared_ptr.h:863
    #14 0x7f7b83a56e01 in std::shared_ptr<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > > std::make_shared<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> >, rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&>(rclcpp::node_interfaces::NodeBaseInterface*&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&) /usr/include/c++/11/bits/shared_ptr.h:879
    #15 0x7f7b83a56e01 in rclcpp::create_publisher_factory<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void>, rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >(rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&)::{lambda(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&)#1}::operator()(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&) const /root/ros2_ws/colcon_ws/src/ros2/rclcpp/rclcpp/include/rclcpp/publisher_factory.hpp:76
    #16 0x7f7b83a56e01 in std::shared_ptr<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > > std::__invoke_impl<std::shared_ptr<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >, rclcpp::create_publisher_factory<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void>, rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >(rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&)::{lambda(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&)#1}&, rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&>(std::__invoke_other, rclcpp::create_publisher_factory<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void>, rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >(rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&)::{lambda(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&)#1}&, rclcpp::node_interfaces::NodeBaseInterface*&&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&) /usr/include/c++/11/bits/invoke.h:61
    #17 0x7f7b83a56e01 in std::enable_if<is_invocable_r_v<std::shared_ptr<rclcpp::PublisherBase>, rclcpp::create_publisher_factory<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void>, rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >(rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&)::{lambda(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&)#1}&, rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&>, std::shared_ptr<rclcpp::PublisherBase> >::type std::__invoke_r<std::shared_ptr<rclcpp::PublisherBase>, rclcpp::create_publisher_factory<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void>, rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >(rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&)::{lambda(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&)#1}&, rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&>(rclcpp::create_publisher_factory<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void>, rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >(rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&)::{lambda(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&)#1}&, rclcpp::node_interfaces::NodeBaseInterface*&&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&) /usr/include/c++/11/bits/invoke.h:116
    #18 0x7f7b83a56e01 in std::_Function_handler<std::shared_ptr<rclcpp::PublisherBase> (rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&), rclcpp::create_publisher_factory<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void>, rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > >(rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&)::{lambda(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&)#1}>::_M_invoke(std::_Any_data const&, rclcpp::node_interfaces::NodeBaseInterface*&&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&) /usr/include/c++/11/bits/std_function.h:291
    #19 0x7f7b83a5f128 in std::function<std::shared_ptr<rclcpp::PublisherBase> (rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&)>::operator()(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&) const /usr/include/c++/11/bits/std_function.h:590
    #20 0x7f7b83a5f128 in rclcpp::node_interfaces::NodeTopics::create_publisher(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::PublisherFactory const&, rclcpp::QoS const&) /root/ros2_ws/colcon_ws/src/ros2/rclcpp/rclcpp/src/rclcpp/node_interfaces/node_topics.cpp:50
    #21 0x7f7b83a143a8 in std::shared_ptr<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > > rclcpp::detail::create_publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void>, rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> >, std::shared_ptr<rclcpp::node_interfaces::NodeTopicsInterface>, std::shared_ptr<rclcpp::node_interfaces::NodeTopicsInterface> >(std::shared_ptr<rclcpp::node_interfaces::NodeTopicsInterface>&, std::shared_ptr<rclcpp::node_interfaces::NodeTopicsInterface>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&) /root/ros2_ws/colcon_ws/src/ros2/rclcpp/rclcpp/include/rclcpp/create_publisher.hpp:65
    #22 0x7f7b83a143a8 in std::shared_ptr<rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> > > rclcpp::create_publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void>, rclcpp::Publisher<rcl_interfaces::msg::ParameterEvent_<std::allocator<void> >, std::allocator<void> >, std::shared_ptr<rclcpp::node_interfaces::NodeTopicsInterface>&>(std::shared_ptr<rclcpp::node_interfaces::NodeTopicsInterface>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&) /root/ros2_ws/colcon_ws/src/ros2/rclcpp/rclcpp/include/rclcpp/create_publisher.hpp:104
    #23 0x7f7b83a143a8 in rclcpp::node_interfaces::NodeParameters::NodeParameters(std::shared_ptr<rclcpp::node_interfaces::NodeBaseInterface>, std::shared_ptr<rclcpp::node_interfaces::NodeLoggingInterface>, std::shared_ptr<rclcpp::node_interfaces::NodeTopicsInterface>, std::shared_ptr<rclcpp::node_interfaces::NodeServicesInterface>, std::shared_ptr<rclcpp::node_interfaces::NodeClockInterface>, std::vector<rclcpp::Parameter, std::allocator<rclcpp::Parameter> > const&, bool, bool, rclcpp::QoS const&, rclcpp::PublisherOptionsBase const&, bool, bool) /root/ros2_ws/colcon_ws/src/ros2/rclcpp/rclcpp/src/rclcpp/node_interfaces/node_parameters.cpp:99
    #24 0x7f7b83983162 in rclcpp::Node::Node(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&, rclcpp::NodeOptions const&) /root/ros2_ws/colcon_ws/src/ros2/rclcpp/rclcpp/src/rclcpp/node.cpp:197
    #25 0x7f7b83988223 in rclcpp::Node::Node(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, rclcpp::NodeOptions const&) /root/ros2_ws/colcon_ws/src/ros2/rclcpp/rclcpp/src/rclcpp/node.cpp:115
    #26 0x7f7b7e576f64 in demo_nodes_cpp::Talker::Talker(rclcpp::NodeOptions const&) /root/ros2_ws/colcon_ws/src/ros2/demos/demo_nodes_cpp/src/topics/talker.cpp:38
    #27 0x7f7b7e5794d3 in void __gnu_cxx::new_allocator<demo_nodes_cpp::Talker>::construct<demo_nodes_cpp::Talker, rclcpp::NodeOptions const&>(demo_nodes_cpp::Talker*, rclcpp::NodeOptions const&) /usr/include/c++/11/ext/new_allocator.h:162
    #28 0x7f7b7e5794d3 in void std::allocator_traits<std::allocator<demo_nodes_cpp::Talker> >::construct<demo_nodes_cpp::Talker, rclcpp::NodeOptions const&>(std::allocator<demo_nodes_cpp::Talker>&, demo_nodes_cpp::Talker*, rclcpp::NodeOptions const&) /usr/include/c++/11/bits/alloc_traits.h:516
    #29 0x7f7b7e5794d3 in std::_Sp_counted_ptr_inplace<demo_nodes_cpp::Talker, std::allocator<demo_nodes_cpp::Talker>, (__gnu_cxx::_Lock_policy)2>::_Sp_counted_ptr_inplace<rclcpp::NodeOptions const&>(std::allocator<demo_nodes_cpp::Talker>, rclcpp::NodeOptions const&) /usr/include/c++/11/bits/shared_ptr_base.h:519
    #30 0x7f7b7e5794d3 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<demo_nodes_cpp::Talker, std::allocator<demo_nodes_cpp::Talker>, rclcpp::NodeOptions const&>(demo_nodes_cpp::Talker*&, std::_Sp_alloc_shared_tag<std::allocator<demo_nodes_cpp::Talker> >, rclcpp::NodeOptions const&) /usr/include/c++/11/bits/shared_ptr_base.h:650
    #31 0x7f7b7e5794d3 in std::__shared_ptr<demo_nodes_cpp::Talker, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<demo_nodes_cpp::Talker>, rclcpp::NodeOptions const&>(std::_Sp_alloc_shared_tag<std::allocator<demo_nodes_cpp::Talker> >, rclcpp::NodeOptions const&) /usr/include/c++/11/bits/shared_ptr_base.h:1342
    #32 0x7f7b7e5794d3 in std::shared_ptr<demo_nodes_cpp::Talker>::shared_ptr<std::allocator<demo_nodes_cpp::Talker>, rclcpp::NodeOptions const&>(std::_Sp_alloc_shared_tag<std::allocator<demo_nodes_cpp::Talker> >, rclcpp::NodeOptions const&) /usr/include/c++/11/bits/shared_ptr.h:409
    #33 0x7f7b7e5794d3 in std::shared_ptr<demo_nodes_cpp::Talker> std::allocate_shared<demo_nodes_cpp::Talker, std::allocator<demo_nodes_cpp::Talker>, rclcpp::NodeOptions const&>(std::allocator<demo_nodes_cpp::Talker> const&, rclcpp::NodeOptions const&) /usr/include/c++/11/bits/shared_ptr.h:863
    #34 0x7f7b7e5794d3 in std::shared_ptr<demo_nodes_cpp::Talker> std::make_shared<demo_nodes_cpp::Talker, rclcpp::NodeOptions const&>(rclcpp::NodeOptions const&) /usr/include/c++/11/bits/shared_ptr.h:879
    #35 0x7f7b7e5794d3 in rclcpp_components::NodeFactoryTemplate<demo_nodes_cpp::Talker>::create_node_instance(rclcpp::NodeOptions const&) /root/ros2_ws/colcon_ws/src/ros2/rclcpp/rclcpp_components/include/rclcpp_components/node_factory_template.hpp:45
    #36 0x55b82f7d87f7 in main /root/ros2_ws/colcon_ws/build/demo_nodes_cpp/rclcpp_components/node_main_talker.cpp:55
    #37 0x7f7b81c3dd8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #38 0x7f7b81c3de3f in __libc_start_main_impl ../csu/libc-start.c:392
    #39 0x55b82f7db5c4 in _start (/root/ros2_ws/colcon_ws/build/demo_nodes_cpp/talker+0xd5c4)

0x60600006c0e0 is located 0 bytes inside of 64-byte region [0x60600006c0e0,0x60600006c120)
allocated by thread T0 here:
    #0 0x7f7b840bc1c7 in operator new(unsigned long) ../../../../src/libsanitizer/asan/asan_new_delete.cpp:99
    #1 0x7f7b82772023 in rcutils_string_map_init /root/ros2_ws/colcon_ws/src/ros2/rcutils/src/string_map.c:67
    #2 0x7f7b8354dc37 in rcl_resolve_name /root/ros2_ws/colcon_ws/src/ros2/rcl/rcl/src/rcl/node_resolve_name.c:47
    #3 0x610000000a3f  (<unknown module>)

SUMMARY: AddressSanitizer: new-delete-type-mismatch ../../../../src/libsanitizer/asan/asan_new_delete.cpp:172 in operator delete(void*, unsigned long)
==726931==HINT: if you don't care about these errors you may set ASAN_OPTIONS=new_delete_type_mismatch=0
==726931==ABORTING
[ros2run]: Process exited with failure 1
@fujitatomoya
Copy link
Collaborator Author

this can also happen with humble branch as well.

@fujitatomoya fujitatomoya added the bug Something isn't working label Jun 20, 2023
@fujitatomoya
Copy link
Collaborator Author

CC: @iuhilnehc-ynos @Barry-Xu-2018

@iuhilnehc-ynos
Copy link
Collaborator

Actually, I noticed this issue a long time ago while adding the zero_allocate.

The deallocate just deallocate buffer size with 1. I don't know how to fix this issue elegantly.
Any suggestion?

@iuhilnehc-ynos
Copy link
Collaborator

iuhilnehc-ynos commented Jul 10, 2023

How about incorporating an additional size field at the beginning of the buffer to store the size value during buffer allocation?

(NOTE: It results in a significant waste of memory when there are numerous small buffer allocations.)

@CursedRock17
Copy link
Contributor

According to cppreference the ending parameter of both allocate and deallocate is a size_type n where n is:

the number of objects to allocate storage for

So is there anyway to extract the size of the typename T given in retyped_deallocate like

std::allocator_traits<Alloc>::deallocate(*typed_allocator, typed_ptr, sizeof(T));

or a some way to find the type of the object that was allocated, or is that beyond the reach of the function.

@iuhilnehc-ynos
Copy link
Collaborator

iuhilnehc-ynos commented Jul 20, 2023

What if the type is char and then rcl uses the allocator to allocate a buffer with count?
Even if we can add an explicit specialization template get_rcl_allocator for char to use rcl_get_default_allocator(), which seems like a workaround, what if using get_rcl_allocator<rcl_node_t> in the future, and then use the allocator to allocate a buffer with count(2)?

It seems that using sizeof(T) can't fix this issue.

@kfabian
Copy link

kfabian commented Dec 8, 2023

I stumbled on this issue, because I encountered problems when I wanted to use ROS2 >= humble with jemalloc. (Apparently I am not the first one: ROS 2 migration stories: The struggles of moving to Humble)

I think std::allocator_traits<Alloc>::deallocate(*typed_allocator, typed_ptr, sizeof(T)); won't work because n is the number of objects of type T to deallocate and not the number of bytes.

I also think that

std::allocator_traits<Alloc>::deallocate(*typed_allocator, typed_ptr, 1);
only works because the default implementation of operator delete(void* ptr, std::size_t size) just calls operator delete(void* ptr) and ignores the size argument. Jemalloc instead explicitly implements a sized delete, which leads to memory errors when used together with rclcpp, because the size argument does not match the previously allocated size. So I wonder if there is a safe way to create an rcl_allocator_t struct from an STL allocator, because the STL allocator requires a size argument for deallocate.

@iluetkeb
Copy link
Contributor

I'm assuming that the C++ standard writers had a good reason to make the number of elements a parameter. Therefore, I would suggest to address this by adding a corresponding method which takes this as an argument. Further, we may want to consider deprecating the existing version of the function that does not have this argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants