Skip to content

Commit 92ece08

Browse files
committed
Core: Fix up file close issue
1 parent 057d314 commit 92ece08

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

volatility3/framework/layers/resources.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,18 @@ def open(self, url: str, mode: str = "rb") -> Any:
179179
except AttributeError:
180180
# If our fp doesn't have an info member, carry on gracefully
181181
content_length = -1
182-
cache_file = open(temp_filename, "wb")
183-
184-
count = 0
185-
block = fp.read(block_size)
186-
while block:
187-
count += len(block)
188-
if self._progress_callback:
189-
self._progress_callback(
190-
count * 100 / max(count, int(content_length)),
191-
f"Reading file {url}",
192-
)
193-
cache_file.write(block)
182+
with open(temp_filename, "wb") as cache_file:
183+
count = 0
194184
block = fp.read(block_size)
195-
cache_file.close()
185+
while block:
186+
count += len(block)
187+
if self._progress_callback:
188+
self._progress_callback(
189+
count * 100 / max(count, int(content_length)),
190+
f"Reading file {url}",
191+
)
192+
cache_file.write(block)
193+
block = fp.read(block_size)
196194
else:
197195
vollog.debug(f"Using already cached file at: {temp_filename}")
198196
# Re-open the cache with a different mode

0 commit comments

Comments
 (0)