Skip to content

Commit 3d01281

Browse files
authored
Fix the leaking file descriptor when returning a z3 smt check result (#1574)
1 parent 916a472 commit 3d01281

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

mythril/laser/smt/solver/solver.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ def check(self, *args) -> z3.CheckSatResult:
5454
:return: The evaluated result which is either of sat, unsat or unknown
5555
"""
5656
old_stdout = sys.stdout
57-
sys.stdout = open(os.devnull, "w")
58-
try:
59-
evaluate = self.raw.check(args)
60-
except z3.z3types.Z3Exception as e:
61-
# Some requests crash the solver
62-
evaluate = z3.unknown
63-
log.info(f"Encountered Z3 exception when checking the constraints: {e}")
57+
with open(os.devnull, "w") as dev_null_fd:
58+
sys.stdout = dev_null_fd
59+
try:
60+
evaluate = self.raw.check(args)
61+
except z3.z3types.Z3Exception as e:
62+
# Some requests crash the solver
63+
evaluate = z3.unknown
64+
log.info(f"Encountered Z3 exception when checking the constraints: {e}")
6465
sys.stdout = old_stdout
6566
return evaluate
6667

0 commit comments

Comments
 (0)