@@ -103,6 +103,7 @@ class goto_checkt
103
103
104
104
void bounds_check (const index_exprt &, const guardt &);
105
105
void div_by_zero_check (const div_exprt &, const guardt &);
106
+ void memory_leak_check (const irep_idt &function_id);
106
107
void mod_by_zero_check (const mod_exprt &, const guardt &);
107
108
void undefined_shift_check (const shift_exprt &, const guardt &);
108
109
void pointer_rel_check (const exprt &, const guardt &);
@@ -1515,6 +1516,30 @@ void goto_checkt::rw_ok_check(exprt &expr)
1515
1516
}
1516
1517
}
1517
1518
1519
+ void goto_checkt::memory_leak_check (const irep_idt &function_id)
1520
+ {
1521
+ const symbolt &leak = ns.lookup (CPROVER_PREFIX " memory_leak" );
1522
+ const symbol_exprt leak_expr = leak.symbol_expr ();
1523
+
1524
+ // add self-assignment to get helpful counterexample output
1525
+ goto_programt::targett t = new_code.add_instruction ();
1526
+ t->make_assignment ();
1527
+ t->code = code_assignt (leak_expr, leak_expr);
1528
+
1529
+ source_locationt source_location;
1530
+ source_location.set_function (function_id);
1531
+
1532
+ equal_exprt eq (leak_expr, null_pointer_exprt (to_pointer_type (leak.type )));
1533
+
1534
+ add_guarded_claim (
1535
+ eq,
1536
+ " dynamically allocated memory never freed" ,
1537
+ " memory-leak" ,
1538
+ source_location,
1539
+ eq,
1540
+ guardt ());
1541
+ }
1542
+
1518
1543
void goto_checkt::goto_check (
1519
1544
goto_functiont &goto_function,
1520
1545
const irep_idt &_mode)
@@ -1713,30 +1738,11 @@ void goto_checkt::goto_check(
1713
1738
}
1714
1739
else if (i.is_end_function ())
1715
1740
{
1716
- if (i.function ==goto_functionst::entry_point () &&
1717
- enable_memory_leak_check)
1741
+ if (
1742
+ i.function == goto_functionst::entry_point () &&
1743
+ enable_memory_leak_check)
1718
1744
{
1719
- const symbolt &leak=ns.lookup (CPROVER_PREFIX " memory_leak" );
1720
- const symbol_exprt leak_expr=leak.symbol_expr ();
1721
-
1722
- // add self-assignment to get helpful counterexample output
1723
- goto_programt::targett t=new_code.add_instruction ();
1724
- t->make_assignment ();
1725
- t->code =code_assignt (leak_expr, leak_expr);
1726
-
1727
- source_locationt source_location;
1728
- source_location.set_function (i.function );
1729
-
1730
- equal_exprt eq (
1731
- leak_expr,
1732
- null_pointer_exprt (to_pointer_type (leak.type )));
1733
- add_guarded_claim (
1734
- eq,
1735
- " dynamically allocated memory never freed" ,
1736
- " memory-leak" ,
1737
- source_location,
1738
- eq,
1739
- guardt ());
1745
+ memory_leak_check (i.function );
1740
1746
}
1741
1747
}
1742
1748
0 commit comments