Repository navigation
Fix leaks in is_well_formed_xpath and c14n inclusive prefixes - #222
Merged
Merged
Conversation
dginev
force-pushed
the
fix/init-parser-entry-points
branch
from
October 7, 2026 12:14
62677ff to
027db0a
Compare
dginev
force-pushed
the
fix/memory-leaks
branch
from
October 7, 2026 12:14
25c198d to
f5d1f76
Compare
…ing leak test Leak audit (every test binary under valgrind --leak-check=full, plus a scan of caller-owned libxml2 results): - `is_well_formed_xpath` released the compiled expression with a plain free, leaking its steps: 8 libxml2 allocations per call. Now `xmlXPathFreeCompExpr`. - `Document::canonicalize` passed `inclusive_ns_prefixes` as `CString::into_raw` strings and never reclaimed them: one Rust allocation per prefix per call. The CStrings now live in a named binding for the call. `tests/leak_tests.rs` needs no valgrind: it routes libxml2 through counting allocators (`xmlMemSetup`) and Rust through a counting global allocator, and asserts repeated calls add no live allocations (with a guard that counting is active). Red before each fix (800 libxml2 allocations over 100 xpath calls; 100 Rust allocations over 50 canonicalizations), green after, on libxml2 2.9.14 and 2.14.1. Remaining valgrind leaks are all detached nodes the tests neither re-attach nor mark `set_rust_owned`, which `unlink_node` documents as leaking by contract; none are library leaks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dginev
force-pushed
the
fix/memory-leaks
branch
from
October 7, 2026 12:21
f5d1f76 to
57ad24c
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Stacked on #221. Merge #220 → #221 → this. Its CHANGELOG lines go into the 0.3.22 section.
Leak audit
I ran every test binary under
valgrind --leak-check=full, and statically checked every libxml2 call whose result the caller must free. Two library leaks turned up:xpath::is_well_formed_xpathfree, leaking its steps. Now usesxmlXPathFreeCompExprDocument::canonicalizewithinclusive_ns_prefixesCString::into_rawstrings were never reclaimed. They now live in a named binding for the callThe other caller-owned results were all freed correctly: serialization buffers, XPath objects and contexts, copied documents, parser contexts, reader strings.
Test without valgrind
tests/leak_tests.rsroutes libxml2 through counting allocators (xmlMemSetup) and Rust through a counting global allocator. It asserts that repeated calls add no live allocations, and a guard checks that counting is actually active.What remains in valgrind is not a library leak
Every remaining leak is a detached node that a test neither re-attaches nor marks
set_rust_owned.unlink_nodedocuments that as leaking by contract. These are subtrees the tests unlink, plus nodes fromNode::new/create_processing_instructionthat are never attached. Cleaning up those tests would let the valgrind job also fail on leaks; that's a follow-up.The full suite (21 test binaries) is valgrind-clean on libxml2 2.9.14 and 2.14.1.
🤖 Generated with Claude Code