ros / ros_comm

ROS communications-related packages, including core client libraries (roscpp, rospy, roslisp) and graph introspection tools (rostopic, rosnode, rosservice, rosparam).
http://wiki.ros.org/ros_comm
762 stars 911 forks source link

Valgrind Memory Error from ROS Publish / Subscribe #1824

Open samxchandlerpi opened 5 years ago

samxchandlerpi commented 5 years ago

I was advised to repost my question on ROS Answers (https://answers.ros.org/question/334010/valgrind-memory-error-from-publish/) here.

I encountered the following error while doing some memory checking on a roscpp node with valgrind. Specifically, I navigated to the node executable and ran it with valgrind while roscore was running in another window.

==16953== Thread 2: ==16953== Syscall param socketcall.sendto(msg) points to uninitialised byte(s) ==16953== at 0x50B19FF: send (send.c:26) ==16953== by 0x53CB800: ros::TransportTCP::write(unsigned char, unsigned int) (in /opt/ros/kinetic/lib/libroscpp.so) ==16953== by 0x53592CA: ros::Connection::writeTransport() (in /opt/ros/kinetic/lib/libroscpp.so) ==16953== by 0x53D181B: ros::TransportTCP::socketUpdate(int) (in /opt/ros/kinetic/lib/libroscpp.so) ==16953== by 0x540E4EF: ros::PollSet::update(int) (in /opt/ros/kinetic/lib/libroscpp.so) ==16953== by 0x5393AC4: ros::PollManager::threadFunc() (in /opt/ros/kinetic/lib/libroscpp.so) ==16953== by 0x6F635D4: ??? (in /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.58.0) ==16953== by 0x50A86B9: start_thread (pthread_create.c:333) ==16953== by 0x635B41C: clone (clone.S:109) ==16953== Address 0xb63506c is 12 bytes inside a block of size 166 alloc'd ==16953== at 0x4C2E80F: operator new[](unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==16953== by 0x4222FB: ros::SerializedMessage ros::serialization::serializeMessage<rovermsgs::Command<std::allocator > >(rovermsgs::Command<std::allocator > const&) (serialization.h:810) ==16953== by 0x42789D: ros::SerializedMessage boost::_bi::list1<boost::reference_wrapper<rovermsgs::Command<std::allocator > const> >::operator()<ros::SerializedMessage, ros::SerializedMessage ()(rovermsgs::Command<std::allocator > const&), boost::_bi::list0>(boost::_bi::type, ros::SerializedMessage (&)(rovermsgs::Command<std::allocator > const&), boost::_bi::list0&, long) (bind.hpp:243) ==16953== by 0x426FB6: boost::_bi::bind_t<ros::SerializedMessage, ros::SerializedMessage ()(rovermsgs::Command<std::allocator > const&), boost::_bi::list1<boost::reference_wrapper<rovermsgs::Command<std::allocator > const> > >::operator()() (bind.hpp:893) ==16953== by 0x426151: boost::detail::function::function_obj_invoker0<boost::_bi::bind_t<ros::SerializedMessage, ros::SerializedMessage ()(rovermsgs::Command<std::allocator > const&), boost::_bi::list1<boost::reference_wrapper<rovermsgs::Command<std::allocator > const> > >, ros::SerializedMessage>::invoke(boost::detail::function::function_buffer&) (function_template.hpp:138) ==16953== by 0x538BA8F: ros::TopicManager::publish(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, boost::function<ros::SerializedMessage ()> const&, ros::SerializedMessage&) (in /opt/ros/kinetic/lib/libroscpp.so) ==16953== by 0x4205CB: void ros::Publisher::publish<rovermsgs::Command<std::allocator > >(rovermsgs::Command<std::allocator > const&) const (publisher.h:118) ==16953== by 0x4E76AC6: RoverJoystick::Command::publish(int, ros::Time) (rover_joystick.h:46) ==16953== by 0x4E71BA0: RoverJoystick::publishPendingData() (rover_joystick.cc:174) ==16953== by 0x4E71989: RoverJoystick::read() (rover_joystick.cc:158) ==16953== by 0x4E71C42: RoverJoystick::readThread(void) (rover_joystick.cc:183) ==16953== by 0x50A86B9: start_thread (pthread_create.c:333) ==16953==

This error only occurs when I subscribe to the publishing topic from this node. This error only occurs once after the first message is published and received by a subscriber. There are no other memory errors in my program. I've also diligently checked for uninitialized memory.

Here are some more details about my setup:

ROS kinetic, Ubuntu 16.04, x86 64 bit Valgrind-3.11.0 and LibVEX Any ideas on what could cause this error are appreciated.

dirk-thomas commented 5 years ago

Please consider to contribute a pull request and/or include reproducible steps.