Skip to content

refactor: resolve TODO to use allocator for rmw_request_id_t in Gener…#3146

Closed
Gelminaio wants to merge 1 commit into
ros2:rollingfrom
Gelminaio:patch-3
Closed

refactor: resolve TODO to use allocator for rmw_request_id_t in Gener…#3146
Gelminaio wants to merge 1 commit into
ros2:rollingfrom
Gelminaio:patch-3

Conversation

@Gelminaio
Copy link
Copy Markdown
Contributor

Description

Resolves an old TODO in GenericClient::create_request_header() where new was used to allocate a C-type structure (rmw_request_id_t).

This PR replaces the new operator with rcutils_get_default_allocator(). It properly allocates the memory using zero_allocate, checks for allocation failure, and provides a custom deleter to the std::shared_ptr to deallocate the memory, aligning with ROS 2 memory management best practices.

Is this user-facing behavior change?

No

Did you use Generative AI?

No

Additional Information

…icClient

Signed-off-by: Pietro Gelmini <86184562+Gelminaio@users.noreply.github.com>
@jmachowinski
Copy link
Copy Markdown
Collaborator

The TODO is just plain wrong. We should not use the C allocator here.

@jmachowinski
Copy link
Copy Markdown
Collaborator

Also, are you sure you did not use AI ?

@Gelminaio
Copy link
Copy Markdown
Contributor Author

Yeah, you got me 😅. To be completely honest, I used Gemini to help me with the exact syntax for the allocator, since I'm still getting used to the ROS 2 memory management internals. I didn't check the AI box because I thought it was meant for fully written by AI, not just snippets. Completely my bad! Good to know that the TODO is just outdated. I'll close this PR right away. Sorry for the noise!

@Gelminaio Gelminaio closed this May 12, 2026
@jmachowinski
Copy link
Copy Markdown
Collaborator

You can modify the PR to remove the todo though...

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