FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
0328 — NetStructure and NetStructureWithConstraints leak their elements and constraint solver at teardown
Class BUG
Severity 1
Status ready

Models: Net/NetStructure, Net/NetStructureWithConstraints

Found: 2026-09-30 review of f42360e..a6492d6 (four parallel correctness reviews)

Decision needed: —

Evidence

NetStructure::~NetStructure (src/net/NetStructure.cpp:188) does not free m_VpNetElements, m_VpCableElements or m_aaiCableConn; NetStructureWithConstraints::~NetStructureWithConstraints (src/net/NetStructureWithConstraints.cpp:283) never deletes m_constraintSolver or m_jointConstr, and with MARE-0317 the solver owns its thread pool (when NumCpuCore > 1). Pre-existing.

Effect

Memory (and, with NumCpuCore > 1, pool threads) leak each time a model is built and destroyed: in tests and in hosts that rebuild models, not in a single run.

Possible fix

Own the elements and the solver with std::unique_ptr (the element classes are now non-copyable, MARE-0318).

Test that would prove it

Build and destroy a NetStructureWithConstraints with NumCpuCore = 2 under valgrind or LeakSanitizer: no leak and no thread left.

Risk

Low; watch for elements shared with the constraint solver.