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

Additional fixes for yadu/raii-client. #304

Merged
merged 3 commits into from
Oct 31, 2024

Conversation

clalancette
Copy link
Collaborator

No description provided.

Copy link
Member

@Yadunund Yadunund left a comment

Choose a reason for hiding this comment

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

Thanks a lot for addressing the outstanding issues with this branch! Left some minor comments to consider.

rmw_zenoh_cpp/src/detail/rmw_client_data.cpp Outdated Show resolved Hide resolved
rmw_zenoh_cpp/src/detail/rmw_client_data.cpp Outdated Show resolved Hide resolved
rmw_zenoh_cpp/src/detail/rmw_client_data.cpp Outdated Show resolved Hide resolved
std::move(request_type_support),
std::move(response_type_support)
});
duplicate_pointers.push_back(client_data);
Copy link
Member

Choose a reason for hiding this comment

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

Why do we store the instantiated client_data ptr in this vector?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we didn't do this, then we could conceivably get the same address over and over again. Consider the case where we have the pointer 0x1 in deleted_clients. The first call to new ClientData might return 0x1. At that point, we'd detect that this is in deleted_clients, and loop around again. But right before we make the second call to new ClientData, we drop the reference to the old one, at which point it may be freed. At that point the allocator might decide to give us address 0x1 again, and we'd never make any progress here.

By holding all of the shared_ptr in a vector like this, we guarantee that the allocator will give us a new address. And then at the end of the function, when std::vector goes out of scope, we'll free all of them.

rmw_zenoh_cpp/src/detail/rmw_client_data.cpp Outdated Show resolved Hide resolved
Copy link
Member

@Yadunund Yadunund left a comment

Choose a reason for hiding this comment

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

Sorry I forgot we need to address the issue with std::move before we can merge. But apart from that, this generally looks good to me.

clalancette and others added 2 commits October 31, 2024 09:00
Co-authored-by: yadunund <[email protected]>
Signed-off-by: Chris Lalancette <[email protected]>
Signed-off-by: Chris Lalancette <[email protected]>
@Yadunund Yadunund merged commit 082e64c into yadu/raii-client Oct 31, 2024
8 checks passed
@Yadunund Yadunund deleted the clalancette/raii-client-fixes branch October 31, 2024 15:51
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.

2 participants