atenpas / gpd_ros

ROS wrapper around GPD
BSD 2-Clause "Simplified" License
57 stars 70 forks source link

Segfault for `rosrun gpd_ros detect_grasps_server` #6

Open aPonza opened 5 years ago

aPonza commented 5 years ago

Initiating the command rosrun gpd_ros detect_grasps_server results in a SIGSEGV with backtrace:

(gdb) bt
#0  0x000000000040e30c in GraspDetectionServer::GraspDetectionServer (this=0xffeffee70, node=...)
    at ~/catkin_ws/src/gpd2_ros/src/gpd_ros/grasp_detection_server.cpp:14
#1  0x000000000040d71e in main (argc=1, argv=<optimized out>)
    at ~/catkin_ws/src/gpd2_ros/src/gpd_ros/grasp_detection_server.cpp:132

and valgrind is saying:

==20809== Invalid read of size 8
==20809==    at 0x40E30C: GraspDetectionServer::GraspDetectionServer(ros::NodeHandle&) (grasp_detection_server.cpp:14)
==20809==    by 0x40D71D: main (grasp_detection_server.cpp:132)
==20809==  Address 0x0 is not stack'd, malloc'd or (recently) free'd

It didn't make much sense (the error was alternating between the std::string constructor and the ros::NodeHandle object) and the culprit is unrelated to the error messages:

https://github.com/atenpas/gpd2_ros/blob/63cec397d5c2ee064f32d21afe373290da5b63fa/src/gpd_ros/grasp_detection_server.cpp#L11

Commenting this line, and it's declaration in https://github.com/atenpas/gpd2_ros/blob/master/include/gpd_ros/grasp_detection_server.h#L103 results in no more segfaults. The variable is uninitialized (and never used anyways) so either a simple

diff --git a/src/gpd_ros/grasp_detection_server.cpp b/src/gpd_ros/grasp_detection_server.cpp
index 171b6d9..94d7e2f 100644
--- a/src/gpd_ros/grasp_detection_server.cpp
+++ b/src/gpd_ros/grasp_detection_server.cpp
@@ -6,7 +6,7 @@ GraspDetectionServer::GraspDetectionServer(ros::NodeHandle& node)
   cloud_camera_ = NULL;

   // set camera viewpoint to default origin
-  std::vector<double> camera_position;
+  auto camera_position = std::vector<double> {0.0, 0.0, 0.0};
   node.getParam("camera_position", camera_position);
   view_point_ << camera_position[0], camera_position[1], camera_position[2];

or deleting the variable, work.