Skip to content

Commit 97091d4

Browse files
committed
Check for memory leaks in C++ new/delete
1 parent dc5b865 commit 97091d4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/ansi-c/library/new.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ inline void __delete(void *ptr)
9999
// non-deterministically record as deallocated
100100
__CPROVER_bool record;
101101
__CPROVER_deallocated=record?ptr:__CPROVER_deallocated;
102+
103+
// detect memory leaks
104+
if(__CPROVER_memory_leak==ptr) __CPROVER_memory_leak=0;
102105
}
103106
}
104107

@@ -128,5 +131,8 @@ inline void __delete_array(void *ptr)
128131
// non-deterministically record as deallocated
129132
__CPROVER_bool record;
130133
__CPROVER_deallocated=record?ptr:__CPROVER_deallocated;
134+
135+
// detect memory leaks
136+
if(__CPROVER_memory_leak==ptr) __CPROVER_memory_leak=0;
131137
}
132138
}

0 commit comments

Comments
 (0)