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

Fix geometric shapes related memory leaks #2138

Merged
merged 2 commits into from
Jun 3, 2020

Conversation

jliukkonen
Copy link
Contributor

Couple fixes to memory leaks caused by raw pointer usage with geometric_shapes objects.

These fixes are related to the efforts and finding in this issue #2075. However, this PR does not fix the leaks reported by @tylerjw, but rather these are new findings made using address sanitizer.

Running address sanitizer revealed couple memory leaks related raw pointer usage with geometric_shapes objects. I added two fixes to this PR since they are both very small.

First fix is wrapping return value of shapes::constructShapeFromText(in) in shared_ptr so that if the geometry being loaded is corrupted or malformed, the constructed shape will always be freed undepending on the code path.

Second fix is removing call to clone() in BodyDecomposition::init(). Prior to the fix, each of the cloned objects was heap allocated and raw pointer was passed to addBody without calling free on the objects at any point, which caused every single object to leak. Looking more closely at the addBody function I realized that there doesn't seem to be any reason to call clone there so I removed the operation altogether. Now, the raw pointers passed to the function point to the shared_ptr<Shape> objects which will get freed correctly eventually thanks to reference counting.

Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address my remark.

@@ -1018,8 +1018,8 @@ bool PlanningScene::loadGeometryFromStream(std::istream& in, const Eigen::Isomet
in >> shape_count;
for (std::size_t i = 0; i < shape_count && in.good() && !in.eof(); ++i)
{
shapes::Shape* s = shapes::constructShapeFromText(in);
if (!s)
const auto shape = shapes::ShapeConstPtr(shapes::constructShapeFromText(in));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are reasonable.

@codecov
Copy link

codecov bot commented Jun 3, 2020

Codecov Report

Merging #2138 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2138      +/-   ##
==========================================
- Coverage   57.79%   57.79%   -0.01%     
==========================================
  Files         328      328              
  Lines       25700    25700              
==========================================
- Hits        14854    14853       -1     
- Misses      10846    10847       +1     
Impacted Files Coverage Δ
...tance_field/src/collision_distance_field_types.cpp 42.68% <100.00%> (ø)
moveit_core/planning_scene/src/planning_scene.cpp 59.47% <100.00%> (ø)
...anning_scene_monitor/src/current_state_monitor.cpp 51.28% <0.00%> (-1.54%) ⬇️
...ipulation/pick_place/src/manipulation_pipeline.cpp 76.41% <0.00%> (-0.95%) ⬇️
...meterization/work_space/pose_model_state_space.cpp 82.31% <0.00%> (-0.69%) ⬇️
...raint_samplers/src/default_constraint_samplers.cpp 82.90% <0.00%> (+0.36%) ⬆️
...nning_scene_monitor/src/planning_scene_monitor.cpp 70.55% <0.00%> (+0.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1ae4318...e99eecd. Read the comment docs.

@rhaschke rhaschke merged commit 9bdce08 into moveit:master Jun 3, 2020
v4hn pushed a commit to v4hn/moveit that referenced this pull request Jul 3, 2020
* Fix memory leak with a shape object when malformed scene geometry file is loaded.
* Fix memory leak by removing unnecessary and leaky call to clone()

(cherry picked from commit 9bdce08)
v4hn pushed a commit to v4hn/moveit that referenced this pull request Jul 3, 2020
* Fix memory leak with a shape object when malformed scene geometry file is loaded.
* Fix memory leak by removing unnecessary and leaky call to clone()

(cherry picked from commit 9bdce08)
rhaschke pushed a commit that referenced this pull request Jul 3, 2020
* Fix memory leak with a shape object when malformed scene geometry file is loaded.
* Fix memory leak by removing unnecessary and leaky call to clone()

(cherry picked from commit 9bdce08)
@tylerjw tylerjw mentioned this pull request Jul 18, 2020
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants