Foundation Classes - Fix bucket array leak in Poly_MergeNodesTool#1336
Open
mbait wants to merge 1 commit into
Open
Foundation Classes - Fix bucket array leak in Poly_MergeNodesTool#1336mbait wants to merge 1 commit into
mbait wants to merge 1 commit into
Conversation
Poly_MergeNodesTool::MergedNodesMap derives from NCollection_BaseMap but defined no destructor. NCollection_BaseMap::~NCollection_BaseMap() is defaulted and relies on subclasses calling Destroy() to free the hash bucket arrays (as NCollection_DataMap and the other collection maps do via Clear(true)), so the bucket array allocated by BeginResize() leaked on every Poly_MergeNodesTool instance. The leak is hit on every STL/OBJ/mesh read that goes through Poly_MergeNodesTool (RWStl_Reader, RWObj) and scales with mesh size: 2 * nbFacets buckets when the facet count is known, or the 995329 bucket default (~8 MB per import on 64-bit) when it is not. The map nodes themselves live in the handle-held NCollection_IncAllocator and were released correctly; only the raw bucket array leaked, which is why LeakSanitizer reports a single direct calloc leak per instance via Standard::Allocate <- NCollection_BaseMap::BeginResize. Add the missing destructor calling Destroy(DataMapNode::delNode, true), matching the idiom used by the other NCollection map classes. Verified with an AddressSanitizer/LeakSanitizer-instrumented host performing StlAPI_Reader::Read() + BRepBndLib query: before the fix LSan reports the direct leak with the stack above; after it the process exits clean.
Member
|
Dear @mbait thank you for your investigation and detection of leak! Thank you for your patch. To proceed with integration, please complete signing CLA process: In case if you already have signed CLA, please share ID that OCCT team shared with your by email after accepting of CLA. |
Author
|
I've submitted the signed CLA, waiting for approval. |
dpasukhi
self-requested a review
July 22, 2026 14:13
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.
Summary
Poly_MergeNodesTool::MergedNodesMapderives fromNCollection_BaseMapbut defines no destructor. The base destructor is= defaultand relies on each subclass callingDestroy()to free the hash bucket arrays (this is whatNCollection_DataMapet al. do viaClear(true)), so the bucket array allocated byNCollection_BaseMap::BeginResize()leaks on everyPoly_MergeNodesToolinstance — i.e. on every STL/OBJ/mesh read that merges nodes (RWStl_Reader,RWObj).The leaked size scales with mesh size:
2 * nbFacetsbuckets when the facet count is known, or the 995329-bucket default (~8 MB per import on 64-bit) when it is not. The map nodes live in the handle-heldNCollection_IncAllocatorand are released correctly — only the raw bucket array leaks.LeakSanitizer evidence
Reported downstream against prebuilt V8_0_0_p1 Release libs (farfield-ru/libocct-build#1); resolved stack (LSan with
fast_unwind_on_malloc=0):A one-triangle ASCII STL leaks 7,962,640 bytes per
StlAPI_Reader::Read()call (the unknown-size default path).Fix
Add the missing destructor calling
Destroy(DataMapNode::delNode, true), matching the idiom used by the otherNCollectionmap classes.Verification
ASan/LSan-instrumented host performing
StlAPI_Reader::Read()+BRepBndLib::Add():Direct leak of 7962640 byte(s) in 1 object(s)with the stack above, nonzero exit;Also rebuilt Release/Debug/RelWithDebInfo shared-library configurations on Linux (GCC 13) and Windows (MSVC, Ninja) with this change applied on top of V8_0_0_p1 — no build or functional regressions observed in STEP/IGES/STL/OBJ import paths.