-
Notifications
You must be signed in to change notification settings - Fork 194
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
NetDefinition: ownership and cleanup (FR-786) #228
Conversation
Codecov Report
@@ Coverage Diff @@
## main #228 +/- ##
==========================================
+ Coverage 99.02% 99.04% +0.01%
==========================================
Files 56 57 +1
Lines 9347 9524 +177
==========================================
+ Hits 9256 9433 +177
Misses 91 91
Continue to review full report at Codecov.
|
0d3ad14
to
0bc84ff
Compare
V2: Split off the new reset code into its own file, add some more comments, fix some style issues ( |
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.
Simon, thank you very much for another excellent PR!
The cleanup of this big memory leak was long overdue.
I am overall +1 on your changes, but left a few inline comments that I'd like to see addressed before we merge this.
src/netdef.c
Outdated
netdef->tunnel.fwmark = 0; | ||
netdef->tunnel.port = 0; |
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.
Same here. This is fine, but we could be using memset()
to keep it in line with the cleanup of the other structs. Then move the netdef->tunnel.mode = NETPLAN_TUNNEL_MODE_UNKNOWN
after memset()
.
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 still undecided between memset()
-ing the substructs vs initializing every component to 0, hence the lack of coherence.
I'll go with memset()
for now to get this out the doors, but in the future I think I'd rather name the structs and use dedicated reset_
functions with explicit defaults for each field. It wouldn't add that much more noise anyway 😁
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.
Yeah.. I was leaning towards explicitly initializing every component to 0 at first as well. But OTOH I also liked the forward-compatibility of memset()
to initialize everything, including future fields, to 0, similar to how g_new0()
creates this data structure in the first place.
I'd be fine with both, I guess :-)
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.
Thanks for the thorough review! There were quite a few nice spots in there, expect a V3 later today with the mentioned changes.
src/netdef.c
Outdated
netdef->tunnel.fwmark = 0; | ||
netdef->tunnel.port = 0; |
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 still undecided between memset()
-ing the substructs vs initializing every component to 0, hence the lack of coherence.
I'll go with memset()
for now to get this out the doors, but in the future I think I'd rather name the structs and use dedicated reset_
functions with explicit defaults for each field. It wouldn't add that much more noise anyway 😁
Some of the strings that were stored in the generated backend settings had unclear ownership, leading to either leaks, double-free, or dangling pointers. This patch forces the duplication in order to simplify handling afterwards, and documents some assumptions that aren't shown through the typesystem (I'm looking at you, GData *).
This centralizes the place where we know about "duid", and makes my life easier when writing reset/freeing code for netdef as I don't have to reallocate a string after I've cleared them all.
ba8777b
to
5127d59
Compare
V3: Addressed comments in review, and tweaked slightly the first patch to document |
Those functions do a full in-depth cleaning and reset each value to its default. I chose to put them in a separate source file as I feel we're getting away from the notion of parsing and much more into the object management after its creation. In all honesty, if the netplan_netdef_new function didn't reference a static data structure, I would have moved it into the new module as well (and probably will in my later API-breaking patchset, but that's a story for another time).
With this patch, we now decide arbitrarily that the owner of the netdef objects is the netdef_ordered list, and all other pointers are weak references. Knowing this, we can now easily clean up all netdefs. Since _ordered is the owner of the global netdefs, it doesn't make sense to change the cur_netdef reference before the new object is in the global array, which is why we do the netdef initialization on a local-only object, which we hand over only after it has been registered in _ordered.
5127d59
to
f3e8308
Compare
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.
Thanks for addressing all my concerns! This looks good to me.
I only left one small inline comment about a dangling pointer to settings->nm.passthrough
, that I'd like to ask you to fix.
Other than that.. as this is a pretty big change, I'd like to run the full suite of (integration) tests on this PR before I merge it. That will probably be tomorrow.
OK, thanks for clarifying the
|
Description
This PR is mostly about cleaning up the NetplanNetDefinition objects, and when to do it. There are a couple of precursor commits that either made the transition easier or fixed some bugs that were uncovered when actually trying to clean up things ;).
There are no API or ABI change, although there's one observable change with the
dhcp_identifier
which now defaults toNULL
instead of an owned string"duid"
. The rationales are in the commit that makes the change.As usual, each commit log contains some context information related to each change, and the commits are split up with the explicit intent of making it easier to review, one commit at a time.
Checklist
make check
successfully.make check-coverage
).