Skip to content

Conversation

@hidmic
Copy link
Contributor

@hidmic hidmic commented Jun 22, 2020

Spin off from #196.

@hidmic hidmic requested review from eboasson and ivanpauno June 22, 2020 20:07
Signed-off-by: Michel Hidalgo <[email protected]>
return RMW_RET_OK;
return ret;
fail:
if (RMW_RET_OK != rmw_init_options_fini(&context->options)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it safe to call fini if init failed? Just checking ...

Copy link
Member

Choose a reason for hiding this comment

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

good point, I think it's not.
@hidmic maybe just returning an error in line 1132.

Copy link
Contributor Author

@hidmic hidmic Jun 23, 2020

Choose a reason for hiding this comment

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

Well, arguably it should not and both rmw_init_options_init() or rmw_init_options_copy() should guarantee output options remain uninitialized. Reality is that such guarantee is not documented in rmw API and most implementations do not really check. rmw_cyclonedds_cpp isn't the exception. Thus the extra fini, which judging by the code isn't unsafe (though again, not necessarily correct nor ideal).

Alternatively, we can establish that guarantee and change implementations to abide to it. Thoughts?

Copy link
Member

@ivanpauno ivanpauno Jun 23, 2020

Choose a reason for hiding this comment

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

Alternatively, we can establish that guarantee and change implementations to abide to it. Thoughts?

👍
If I call *_init() or *_copy() and the function fails, I expect it to cleanup all the resources it created (and not having to do it manually).
In the case of *_copy(src, dst), I also expect the function to no modify *dst if it failed to do the copy (if this cannot be guaranteed, it should be documented).

It's the more usual pattern in C code IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hidmic
Copy link
Contributor Author

hidmic commented Jun 25, 2020

This has been superseded by #202.

@hidmic hidmic closed this Jun 25, 2020
@hidmic hidmic deleted the hidmic/avoid-context-options-leaks branch June 25, 2020 15:33
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.

4 participants