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

add auto cleanup helper for nl_object and use it #402

Closed
wants to merge 3 commits into from

Conversation

KanjiMonster
Copy link
Contributor

Add a auto cleanup helper for nl_object, and use it where appropriate for cache and xfrm.

Add a helper for automatically cleaning up a nl_object reference.

Signed-off-by: Jonas Gorski <[email protected]>
Use the new _nl_auto_nl_object helper for cache where appropriate. Make
sure to initialze *old to NULL in cache_include() as we do not
initialize it in the error path for unknown actions.

Signed-off-by: Jonas Gorski <[email protected]>
Analogue to the change for cache_include(), use the new helper for
nl_objects and initialize old to NULL since we do not use it for other
messages than XFRM_MSG_EXPIRE.

Signed-off-by: Jonas Gorski <[email protected]>
thom311 added a commit that referenced this pull request Sep 12, 2024
@thom311
Copy link
Owner

thom311 commented Sep 12, 2024

merged as d48da13.

Thank you for the patch.

IMO this again shows just how useful the cleanup attribute is. While in theory everybody can reason about the proper places where to call free/unref/put, in practice it is a very error prone effort. Instead, we should be explicit about ownership transfer with the trifecta _nl_steal_pointer(), _nl_clear_pointer() and _nl_auto*. Also, the features that gcc/clang provide on top of standard C, make it worth to depend on some of them.

@thom311 thom311 closed this Sep 12, 2024
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