@@ -181,6 +181,7 @@ class goto_check_ct
181
181
void undefined_shift_check (const shift_exprt &, const guardt &);
182
182
void pointer_rel_check (const binary_exprt &, const guardt &);
183
183
void pointer_overflow_check (const exprt &, const guardt &);
184
+ void memory_leak_check (const irep_idt &function_id);
184
185
185
186
// / Generates VCCs for the validity of the given dereferencing operation.
186
187
// / \param expr the expression to be checked
@@ -2045,6 +2046,28 @@ optionalt<exprt> goto_check_ct::expand_pointer_checks(exprt expr)
2045
2046
return {};
2046
2047
}
2047
2048
2049
+ void goto_check_ct::memory_leak_check (const irep_idt &function_id)
2050
+ {
2051
+ const symbolt &leak = ns.lookup (CPROVER_PREFIX " memory_leak" );
2052
+ const symbol_exprt leak_expr = leak.symbol_expr ();
2053
+
2054
+ // add self-assignment to get helpful counterexample output
2055
+ new_code.add (goto_programt::make_assignment (leak_expr, leak_expr));
2056
+
2057
+ source_locationt source_location;
2058
+ source_location.set_function (function_id);
2059
+
2060
+ equal_exprt eq (leak_expr, null_pointer_exprt (to_pointer_type (leak.type )));
2061
+
2062
+ add_guarded_property (
2063
+ eq,
2064
+ " dynamically allocated memory never freed" ,
2065
+ " memory-leak" ,
2066
+ source_location,
2067
+ eq,
2068
+ identity);
2069
+ }
2070
+
2048
2071
void goto_check_ct::goto_check (
2049
2072
const irep_idt &function_identifier,
2050
2073
goto_functiont &goto_function)
@@ -2225,24 +2248,7 @@ void goto_check_ct::goto_check(
2225
2248
function_identifier == goto_functionst::entry_point () &&
2226
2249
enable_memory_leak_check)
2227
2250
{
2228
- const symbolt &leak = ns.lookup (CPROVER_PREFIX " memory_leak" );
2229
- const symbol_exprt leak_expr = leak.symbol_expr ();
2230
-
2231
- // add self-assignment to get helpful counterexample output
2232
- new_code.add (goto_programt::make_assignment (leak_expr, leak_expr));
2233
-
2234
- source_locationt source_location;
2235
- source_location.set_function (function_identifier);
2236
-
2237
- equal_exprt eq (
2238
- leak_expr, null_pointer_exprt (to_pointer_type (leak.type )));
2239
- add_guarded_property (
2240
- eq,
2241
- " dynamically allocated memory never freed" ,
2242
- " memory-leak" ,
2243
- source_location,
2244
- eq,
2245
- identity);
2251
+ memory_leak_check (function_identifier);
2246
2252
}
2247
2253
}
2248
2254
0 commit comments