Skip to content

Commit 3727c93

Browse files
authored
Add ELF.close() to release resources (#2444)
* Add ELF.close() to release resources `ELFFile.close()` just closes the mmap'd file, but our own wrapper keeps the file handle open. This is annoying when using a temporary file on Windows since they can't be deleted if there is a dangling handle. This can be used together with the inherited context manager from ELFFile. * Update CHANGELOG
1 parent bc453b4 commit 3727c93

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ The table below shows which release corresponds to each branch, and what date th
7474

7575
- [#2358][2358] Cache output of `asm()`
7676
- [#2457][2457] Catch exception of non-ELF files in checksec.
77+
- [#2444][2444] Add `ELF.close()` to release resources
7778

7879
[2358]: https://github.com/Gallopsled/pwntools/pull/2358
7980
[2457]: https://github.com/Gallopsled/pwntools/pull/2457
81+
[2444]: https://github.com/Gallopsled/pwntools/pull/2444
8082

8183
## 4.14.0 (`beta`)
8284

pwnlib/elf/elf.py

+8
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,14 @@ def __init__(self, path, checksec=True):
364364
self._libs = None
365365
self._maps = None
366366

367+
def close(self):
368+
"""close() -> None
369+
370+
Close the ELF file and release all resources associated with it.
371+
"""
372+
super(ELF, self).close()
373+
self.file.close()
374+
367375
@staticmethod
368376
@LocalContext
369377
def from_assembly(assembly, *a, **kw):

0 commit comments

Comments
 (0)