Conversation
|
You need to build z3 with Leak detection on using the address sanitizer, such as -fsanitize=address and other flags that are required for leak detection. Figure out what are the right flags before building z3. |
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
I've built Z3 with address sanitizer using Testing revealed that my initial fix was partial - it reduced leaks from 19520 bytes in 151 allocations to 19360 bytes in 141 allocations. The main issue was that the lar_solver destructor was missing With the complete fix (commit 43c35e4), Z3 now runs cleanly with no memory leaks detected by AddressSanitizer. |
* Initial plan for issue * Initial analysis of memory leak issue Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Fix memory leak in lar_solver by adding var_register cleanup Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Complete memory leak fix: add dealloc(m_imp) to lar_solver destructor Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> * Delete leak.smt2 * Update lar_solver.cpp --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com> Co-authored-by: Nikolaj Bjorner <nbjorner@microsoft.com>
Starting investigation of memory leaks in Z3 solver. The issue shows two main leak sources:
src/util/heap.hand vector expansion insrc/util/vector.hsrc/util/memory_manager.cppAnalysis Complete
Based on the stack traces, the leaks appear to be:
Heap allocation leak:
heap<lp::lpvar_lt>::set_bounds->heap constructor->vector resize->vector expand_vector->memory::reallocateVar register leak:
var_register::add_var-> unordered_map allocation in lar_solverRoot Cause Identified
The memory leaks occur because:
theory_lra::imp::init(), the solver callsget_one()andget_zero()which create variables viaadd_const()lar_solver::add_var()being called, which callsm_imp->m_var_register.add_var()var_register::add_var()method adds entries tom_external_to_local(unordered_map) andm_local_to_external(vector)var_registerclass has aclear()method, it's not being called during cleanuplar_solverdestructor only deletes terms but doesn't clean up the var_register data structuresFix Applied
Added a call to
m_imp->m_var_register.clear()in thelar_solver::~lar_solver()destructor to properly clean up the var_register's data structures including the unordered_map and vector.The fix is minimal and surgical - it only adds one line to ensure proper cleanup of the var_register when the lar_solver is destroyed.
Fixes #7690.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.