mirror of
https://github.com/Z3Prover/z3
synced 2026-08-03 04:33:28 +00:00
Prevent Z3_solver_reset abort after memory_max_size OOM by making reset memory-limit-safe (#10254)
`memory_max_size` OOMs were recoverable at `check_sat` time
(`Z3_L_UNDEF` + error handler), but `Z3_solver_reset` could still
terminate the process with an uncaught `out_of_memory_error`. This
change keeps reset on the C API error-reporting path instead of letting
teardown allocations trip the same hard limit.
- **Reset path hardening**
- `Z3_solver_reset` now performs solver teardown under a temporary
suspension of the global memory cap, then restores the previous cap
afterward.
- This avoids aborts when allocator accounting is still above
`memory_max_size` at reset time.
- **Memory manager support**
- Added `memory::get_max_size()` to snapshot/restore the active cap
precisely.
- **Regression coverage**
- Extended `src/test/memory.cpp` with a focused scenario that trips
`Z3_MEMOUT_FAIL` and then calls `Z3_solver_reset` under a non-throwing
error handler, covering the previously aborting recovery path.
```cpp
struct scoped_memory_limit_reset {
size_t m_prev_max;
scoped_memory_limit_reset(): m_prev_max(memory::get_max_size()) {
memory::set_max_size(0);
}
~scoped_memory_limit_reset() {
memory::set_max_size(m_prev_max);
}
} scoped_max_memory;
```
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes #10250
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
parent
ad4896c3e0
commit
aa0ebc6efc
4 changed files with 57 additions and 1 deletions
|
|
@ -143,6 +143,11 @@ void memory::set_max_size(size_t max_size) {
|
|||
g_memory_max_size = max_size;
|
||||
}
|
||||
|
||||
size_t memory::get_max_size() {
|
||||
lock_guard lock(*g_memory_mux);
|
||||
return g_memory_max_size <= 0 ? 0 : static_cast<size_t>(g_memory_max_size);
|
||||
}
|
||||
|
||||
void memory::set_max_alloc_count(size_t max_count) {
|
||||
g_memory_max_alloc_count = max_count;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ public:
|
|||
static void set_high_watermark(size_t watermak);
|
||||
static bool above_high_watermark();
|
||||
static void set_max_size(size_t max_size);
|
||||
static size_t get_max_size();
|
||||
static void set_max_alloc_count(size_t max_count);
|
||||
static void finalize(bool shutdown = true);
|
||||
static void display_max_usage(std::ostream& os);
|
||||
|
|
@ -157,4 +158,3 @@ inline std::ostream & operator<<(std::ostream & out, mem_stat const & m) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue