rclcpp icon indicating copy to clipboard operation
rclcpp copied to clipboard

address sanitizer complains new-delete-type-mismatch over allocator_common

Open tsingakbar opened this issue 3 years ago • 2 comments

Bug report

Required Info:

Steps to reproduce issue

build humble according to official guide enabling address sanitizer, like this:

colcon build --packages-up-to examples_rclcpp_minimal_publisher --cmake-args -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=OFF -DCMAKE_C_FLAGS="-fno-omit-frame-pointer -fsanitize=address" -DCMAKE_CXX_FLAGS="-fno-omit-frame-pointer -fsanitize=address"

Then launch the shipped example after source installed setup.bash: RMW_IMPLEMENTATION=rmw_fastrtps_cpp ASAN_OPTIONS=detect_leaks=0 install/examples_rclcpp_minimal_publisher/lib/examples_rclcpp_minimal_publisher/publisher_lambda

Expected behavior

no address sanitizer problems.

Actual behavior

Then address sanitizer reports new-delete-type-mismatch, which is always related to https://github.com/ros2/rclcpp/blob/humble/rclcpp/include/rclcpp/allocator/allocator_common.hpp#L67 .

template<typename Alloc> void * retyped_allocate(size_t size, void * untyped_allocator);
template<typename T, typename Alloc> void retyped_deallocate(void * untyped_pointer, void * untyped_allocator);

Mostly retyped_allocate is called with a size greater than 1, but later calling retyped_deallocate will internally always use 1 as size to dealloc.

Additional information

tsingakbar avatar Nov 08 '22 12:11 tsingakbar

related to https://github.com/ros2/rclcpp/pull/1324, duplicate of https://github.com/ros2/rclcpp/issues/1925

fujitatomoya avatar Nov 08 '22 19:11 fujitatomoya

Here is my attempt at rebasing the stale PR created to fix this bug. It would be wonderful to be able to use ASAN with ROS.

  • https://github.com/ros2/rclcpp/pull/2046

tylerjw avatar Nov 12 '22 19:11 tylerjw