ros-drivers / urg_node

ROS wrapper for the Hokuyo urg_c library.
Other
101 stars 147 forks source link

Prevent diagnostics segfault by accessing empty urg_ pointer #107

Closed richardw347 closed 1 year ago

richardw347 commented 1 year ago

This PR prevents a potential segfault in the populateDiagnostics function, when the driver disconnects the urg_ pointer is reset. If the diagnostics function is in the middle of execution (it runs in a separate thread) at the time it will try to call a function on an empty pointer. This happened more frequently before PR-102 but it still could potentially happen.

The populateDiagnostics function is accessing urg for things that are static or it already has access to via local variables so I've just refactored the function so it only accesses urg to check if it exists.

Really happy to have other opinions on the solution for this one I just didn't want to add another lock just for diagnostics.