Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file leak in QEMU tracer #138

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions archr/analyzers/qemu_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ def fire_context(
r.halfway_core_path = local_halfway_core_filename

if target_trace_filename:
temp_trace_file = tempfile.mktemp(dir="/tmp", prefix="tracer-")
self.target.copy_file(target_trace_filename, temp_trace_file)
trace_fh = open(temp_trace_file, "rb")
temp_trace_file = tempfile.NamedTemporaryFile()
self.target.copy_file(target_trace_filename, temp_trace_file.name)
trace_fh = open(temp_trace_file.name, "rb")

# Find where qemu loaded the binary. Primarily for PIE
try:
Expand Down Expand Up @@ -303,6 +303,8 @@ def fire_context(

lastline = entry
bbl_trace_fh.close()
trace_fh.close()
temp_trace_file.close()
r.trace = QEMUBBLTrace(bbl_trace_file.name, bbl_trace_len)

if r.crashed:
Expand Down