Skip to content

Commit 774fb0a

Browse files
committed
Check for memory leaks in C++ new/delete
1 parent e71f30e commit 774fb0a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/ansi-c/library/new.c

+6
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ inline void __delete(void *ptr)
9393
// non-deterministically record as deallocated
9494
__CPROVER_bool record=__VERIFIER_nondet___CPROVER_bool();
9595
__CPROVER_deallocated=record?ptr:__CPROVER_deallocated;
96+
97+
// detect memory leaks
98+
if(__CPROVER_memory_leak==ptr) __CPROVER_memory_leak=0;
9699
}
97100
}
98101

@@ -124,5 +127,8 @@ inline void __delete_array(void *ptr)
124127
// non-deterministically record as deallocated
125128
__CPROVER_bool record=__VERIFIER_nondet___CPROVER_bool();
126129
__CPROVER_deallocated=record?ptr:__CPROVER_deallocated;
130+
131+
// detect memory leaks
132+
if(__CPROVER_memory_leak==ptr) __CPROVER_memory_leak=0;
127133
}
128134
}

0 commit comments

Comments
 (0)