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.
cc @triptec - another one to review.
I got lucky and found the trick to running valgrind in my other project (which keeps evolving as new features appear in nightly), more in the issue for anyone interested.
And that revealed that using
Node::mock()
in an implementation of theDefault
trait is leaking memory - albeit tiny amounts.So in this PR I finally did the C approach properly - I added
Node::null()
method, which uses aptr::null_mut
, and added an internal sibling of that method forDocumentRef
. So now there is a memory-free placeholder node, which is more appropriate for my use case.One could argue that the other project has an API mistake, and should really use an
Option<Node>
instead, but that makes the entire API way too cumbersome. In fact what I really want is aPartialDefault
trait, as I would love to provide fallbacks for all fields except the node... But that's a brainstorm for another day.I also added some recent clippy lint suggestions, and a new test. And naturally verified that no memory is leaked after refactoring to using
Node::null()
, which is happily indeed the case.