Skip to content

Commit cf7566a

Browse files
committed
Fix massive memory leak
1 parent 6492eea commit cf7566a

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

liquidjava-verifier/src/main/java/liquidjava/smt/SMTEvaluator.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ public void verifySubtype(Predicate subRef, Predicate supRef, Context c)
2020

2121
try {
2222
Expression exp = toVerify.getExpression();
23-
TranslatorToZ3 tz3 = new TranslatorToZ3(c);
24-
// com.microsoft.z3.Expr
25-
Expr<?> e = exp.eval(tz3);
26-
Status s = tz3.verifyExpression(e);
27-
if (s.equals(Status.SATISFIABLE)) {
28-
// System.out.println("result of SMT: Not Ok!");
29-
throw new TypeCheckError(subRef + " not a subtype of " + supRef);
23+
Status s;
24+
try (TranslatorToZ3 tz3 = new TranslatorToZ3(c)) {
25+
// com.microsoft.z3.Expr
26+
Expr<?> e = exp.eval(tz3);
27+
s = tz3.verifyExpression(e);
28+
29+
if (s.equals(Status.SATISFIABLE)) {
30+
// System.out.println("result of SMT: Not Ok!");
31+
throw new TypeCheckError(subRef + " not a subtype of " + supRef);
32+
}
3033
}
3134
// System.out.println("result of SMT: Ok!");
3235

liquidjava-verifier/src/main/java/liquidjava/smt/TranslatorToZ3.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import liquidjava.processor.context.AliasWrapper;
2323

24-
public class TranslatorToZ3 {
24+
public class TranslatorToZ3 implements AutoCloseable {
2525

2626
private com.microsoft.z3.Context z3 = new com.microsoft.z3.Context();
2727
private Map<String, Expr<?>> varTranslation = new HashMap<>();
@@ -37,7 +37,6 @@ public TranslatorToZ3(liquidjava.processor.context.Context c) {
3737
TranslatorContextToZ3.addGhostStates(z3, c.getGhostState(), funcTranslation);
3838
}
3939

40-
@SuppressWarnings("unchecked")
4140
public Status verifyExpression(Expr<?> e) throws Exception {
4241
Solver s = z3.mkSolver();
4342
// s.add((BoolExpr) e.eval(this));
@@ -266,4 +265,9 @@ public Expr<?> makeIte(Expr<?> c, Expr<?> t, Expr<?> e) {
266265
return z3.mkITE((BoolExpr) c, t, e);
267266
throw new RuntimeException("Condition is not a boolean expression");
268267
}
268+
269+
@Override
270+
public void close() throws Exception {
271+
z3.close();
272+
}
269273
}

0 commit comments

Comments
 (0)