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

[nav2_util/service_client.hpp] Potential memory leak when request times out #3477

Closed
oysstu opened this issue Mar 15, 2023 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@oysstu
Copy link
Contributor

oysstu commented Mar 15, 2023

https://github.com/ros-planning/navigation2/blob/b499116e017ccdbf13a8ba57c303aae54708dfc0/nav2_util/include/nav2_util/service_client.hpp#L79-L85

Came across this part of the service client code, and it seems like there may be a potential memory leak here if the spin_until_future_complete call times out. According to the documentation for async_send_request, Client::remove_pending_request must be called in the event that the executor stops spinning before the request has completed.

See documentation for async_send_request below
https://github.com/ros2/rclcpp/blob/cbd48c0eb481cdf5d17b2ca056d4596df8b0af1c/rclcpp/include/rclcpp/client.hpp#L587-L591

@SteveMacenski
Copy link
Member

Thanks for the note! Is that something you’d be open to contributing a pull request to fix?

@oysstu
Copy link
Contributor Author

oysstu commented Mar 16, 2023

Seems like an easy enough fix, I've created the PR. The docs do not explicitly mention what to do if FutureReturnCode::INTERRUPTED is returned, but seems likely that it also must be cleaned up since the request has not been processed. The remove_pending_request simply calls erase with the request id on an unordered map, which does nothing if the key doesn't exist.

@SteveMacenski
Copy link
Member

Merged! Thanks for the note :-)

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

No branches or pull requests

2 participants