1
$\begingroup$

I am writing a custom type support which uses the C type support to save work. Unfortunately I failed to find exact documentation about using the C type support which left me with this question:

Has a message to be initialized before being passed to rcl_take?

I looked at the rclc example which initialized the message but the documentation for rcl_take says that only an allocated struct is required in which the taken message will be copied, which would lead to a memory leak if there is already a message with pointers to allocated arrays stored there.

$\endgroup$

1 Answer 1

1
$\begingroup$

It should be initialized, and therefore all fields should be initialized, including strings and sequences. The type support code is responsible for resizing, or finalizing and then re-initializing, fields as needed.

The docs don’t explicitly say initialized, and perhaps they should (tag me on a pr if you’d like to add that), but the implication is that you shouldn’t pass in uninitialized memory, otherwise it’s impossible to tell if the complex fields like strings and such need to be cleaned up first.

Consider that it’s also perfectly legitimate use case for a user to allocate one message on the stack, initialize it once (which is done automatically in C++), and then call take on it over and over again, reusing the message each time.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.