-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[WIP] Leaks #7691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Leaks #7691
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.h
and vector expansion insrc/util/vector.h
src/util/memory_manager.cpp
Analysis 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::reallocate
Var 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_register
class has aclear()
method, it's not being called during cleanuplar_solver
destructor 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.