Skip to content

Commit b58a1a5

Browse files
peterschrammeltautschnig
authored andcommitted
Factor out memory leak instrumentation into separate function
1 parent d932d6f commit b58a1a5

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/ansi-c/goto_check_c.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class goto_check_ct
181181
void undefined_shift_check(const shift_exprt &, const guardt &);
182182
void pointer_rel_check(const binary_exprt &, const guardt &);
183183
void pointer_overflow_check(const exprt &, const guardt &);
184+
void memory_leak_check(const irep_idt &function_id);
184185

185186
/// Generates VCCs for the validity of the given dereferencing operation.
186187
/// \param expr the expression to be checked
@@ -2045,6 +2046,28 @@ optionalt<exprt> goto_check_ct::expand_pointer_checks(exprt expr)
20452046
return {};
20462047
}
20472048

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+
20482071
void goto_check_ct::goto_check(
20492072
const irep_idt &function_identifier,
20502073
goto_functiont &goto_function)
@@ -2225,24 +2248,7 @@ void goto_check_ct::goto_check(
22252248
function_identifier == goto_functionst::entry_point() &&
22262249
enable_memory_leak_check)
22272250
{
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);
22462252
}
22472253
}
22482254

0 commit comments

Comments
 (0)