-
Notifications
You must be signed in to change notification settings - Fork 163
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 rcl arguments' API memory leaks and bugs. #778
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I agree with this logic, or, at least, I don't understand.
It looks to me with this change that we always cleanup output_rule, but that seems weird; we don't
remap_init
it in this method. Shouldn't that be the responsibility of the caller?In other words, it kind of looks to me like this method should be:
And then the caller is responsible for
remap_fini
as appropriate. Could you explain a little more what the idea is here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only when something fails.
We do, right above. Thing is,
remap_init
doesn't exist.Right now it's not necessary.
_rcl_remap_parse_rule
takes a zero-initializedrcl_remap_t
instance. On failure, it should stay zero-initialized.It could be the case, but with the current
rcl_remap_t
structure and API implementation it doesn't add much value. The init/fini cycle would still be coupled to the parse API. However, ifrcl_remap_parse()
was capable of reusingrcl_remap_t
structures (i.e. reuse past allocations), and if there was anrcl_remap_move()
API to copy rules cheaply, then relocating the init/fini cycle could save up quite a few unnecessary allocation/deallocation cycles. I didn't want to go that far.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, now I see. OK, so that block of code is essentially
remap_init
, it just doesn't have that name.I see. So this PR is a cleanup of the allocated memory on failure further down.
I still find the way this is done weird. The
rcl_remap_t
is currently an "inout" parameter, but it seems to me that it should just be an "out" parameter. If we consider it more like that, then the caller can pass it in uninitialized. This method would initialize it and add to it on success, and the caller would (eventually) need to free it. On error, the parameter would still be considered "uninitialized".The above just makes more sense to me. That being said, I don't know how much you want to refactor this here. So I'll leave it up to you whether you want to do that or just go with this code as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly.
That's almost exactly how it is handled right now, except that
_rcl_remap_parse_rule
does not explicitly zero-initialize the givenrcl_remap_t
structure, it assumes it is. So in a way it is an output parameter.