mirror of
				https://github.com/Z3Prover/z3
				synced 2025-11-03 21:09:11 +00:00 
			
		
		
		
	change behavior on allocation excess to process exit to avoid memory smashes on exception unsafe code blocks. Fixes issue #175
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
		
							parent
							
								
									fdef17683a
								
							
						
					
					
						commit
						b4d0e6076e
					
				
					 2 changed files with 17 additions and 16 deletions
				
			
		| 
						 | 
				
			
			@ -258,11 +258,21 @@ public:
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool is_var_const_pair(expr* e, expr* c, unsigned& k) {
 | 
			
		||||
        rational r;
 | 
			
		||||
        if (is_uninterp_const(e) && a.is_numeral(c, r) && r.is_unsigned() && !m_nonfd.is_marked(e)) {
 | 
			
		||||
            k = r.get_unsigned();
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bool is_upper(expr* f) {
 | 
			
		||||
        expr* e1, *e2;
 | 
			
		||||
        rational r;
 | 
			
		||||
        if ((a.is_le(f, e1, e2) || a.is_ge(f, e2, e1)) && 
 | 
			
		||||
            is_uninterp_const(e1) && a.is_numeral(e2, r) && r.is_unsigned() && !m_nonfd.is_marked(e1)) {
 | 
			
		||||
        unsigned k;
 | 
			
		||||
        if ((a.is_le(f, e1, e2) || a.is_ge(f, e2, e1)) && is_var_const_pair(e1, e2, k)) {
 | 
			
		||||
            SASSERT(m_bounds.has_upper(e1));
 | 
			
		||||
            return true;
 | 
			
		||||
        } 
 | 
			
		||||
| 
						 | 
				
			
			@ -271,9 +281,8 @@ public:
 | 
			
		|||
 | 
			
		||||
    bool is_lower(expr* f) {
 | 
			
		||||
        expr* e1, *e2;
 | 
			
		||||
        rational r;
 | 
			
		||||
        if ((a.is_le(f, e1, e2) || a.is_ge(f, e2, e1)) && 
 | 
			
		||||
            is_uninterp_const(e2) && a.is_numeral(e1, r) && r.is_unsigned() && !m_nonfd.is_marked(e2)) {
 | 
			
		||||
        unsigned k;
 | 
			
		||||
        if ((a.is_le(f, e1, e2) || a.is_ge(f, e2, e1)) && is_var_const_pair(e2, e1, k)) {
 | 
			
		||||
            SASSERT(m_bounds.has_lower(e2));
 | 
			
		||||
            return true;
 | 
			
		||||
        } 
 | 
			
		||||
| 
						 | 
				
			
			@ -284,7 +293,6 @@ public:
 | 
			
		|||
        return is_lower(f) || is_upper(f);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    void collect_fd(expr* f) {
 | 
			
		||||
        if (is_bound(f)) return;
 | 
			
		||||
        m_todo.push_back(f);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,8 +33,6 @@ void mem_finalize();
 | 
			
		|||
out_of_memory_error::out_of_memory_error():z3_error(ERR_MEMOUT) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exceeded_memory_allocations::exceeded_memory_allocations():z3_error(ERR_ALLOC_EXCEEDED) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static volatile bool g_memory_out_of_memory  = false;
 | 
			
		||||
static bool       g_memory_initialized       = false;
 | 
			
		||||
| 
						 | 
				
			
			@ -69,13 +67,8 @@ static void throw_out_of_memory() {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
static void throw_alloc_counts_exceeded() {
 | 
			
		||||
    #pragma omp critical (z3_memory_manager) 
 | 
			
		||||
    {
 | 
			
		||||
        // reset the count to avoid re-throwing while
 | 
			
		||||
        // the exception is being thrown.
 | 
			
		||||
        g_memory_alloc_count = 0;
 | 
			
		||||
    }
 | 
			
		||||
    throw exceeded_memory_allocations();
 | 
			
		||||
    std::cout << "Maximal allocation counts " << g_memory_max_alloc_count << " have been exceeded\n";
 | 
			
		||||
    exit(ERR_ALLOC_EXCEEDED);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue