From 922ad16213970138b05ef21ab36eaee3786f92f9 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Sat, 21 Nov 2020 22:32:41 +0100 Subject: [PATCH] if more memory is deallocated than allocated set memtracer to 0 not negative values --- libsrc/core/paje_trace.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/libsrc/core/paje_trace.cpp b/libsrc/core/paje_trace.cpp index 4e387ec2..9b4ac053 100644 --- a/libsrc/core/paje_trace.cpp +++ b/libsrc/core/paje_trace.cpp @@ -967,12 +967,19 @@ namespace ngcore else { if(ev.size > mem_allocated) - std::cerr << "Error in memory tracer: have total allocated memory < 0" << std::endl; + { + std::cerr << "Error in memory tracer: have total allocated memory < 0" << std::endl; + mem_allocated = 0; + } + else + mem_allocated -= ev.size; if(ev.size > mem_allocated_id[ev.id]) - std::cerr << "Error in memory tracer: have allocated memory < 0 in tracer " << names[ev.id] << std::endl; - - mem_allocated -= ev.size; - mem_allocated_id[ev.id] -= ev.size; + { + std::cerr << "Error in memory tracer: have allocated memory < 0 in tracer " << names[ev.id] << std::endl; + mem_allocated_id[ev.id] = 0; + } + else + mem_allocated_id[ev.id] -= ev.size; } } @@ -985,7 +992,12 @@ namespace ngcore if(ev.is_alloc) mem_allocated_id[ev.id] += ev.size; else - mem_allocated_id[ev.id] -= ev.size; + { + if(ev.size > mem_allocated_id[ev.id]) + mem_allocated_id[ev.id] = 0; + else + mem_allocated_id[ev.id] -= ev.size; + } } TreeNode root;