Skip to content

Commit

Permalink
fixup! [fix] SquashFSMountSource: Avoid resource leakage
Browse files Browse the repository at this point in the history
  • Loading branch information
mxmlnkn committed Oct 12, 2024
1 parent 5cc8ace commit f2d4761
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions core/ratarmountcore/SquashFSMountSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,31 @@ def _createIndex(self) -> None:
def __exit__(self, exception_type, exception_value, exception_traceback):
super().__exit__(exception_type, exception_value, exception_traceback)
self.rawFileObject.close()
self.image.close()

# There is no "closed" method and it can only be closed once, else we get:
# PySquashfsImage/__init__.py", line 131, in close
# self._fd.close()
# ^^^^^^^^^^^^^^
# AttributeError: 'NoneType' object has no attribute 'close'
try:
self.image.close()
except AttributeError:
pass

def __del__(self):
if hasattr(self, 'rawFileObject') and not self.rawFileObject.closed:
self.rawFileObject.close()
if hasattr(self, 'image') and not self.image.closed:
self.image.close()

# There is no "closed" method and it can only be closed once, else we get:
# PySquashfsImage/__init__.py", line 131, in close
# self._fd.close()
# ^^^^^^^^^^^^^^
# AttributeError: 'NoneType' object has no attribute 'close'
try:
if hasattr(self, 'image'):
self.image.close()
except AttributeError:
pass

@overrides(MountSource)
def open(self, fileInfo: FileInfo, buffering=-1) -> IO[bytes]:
Expand Down

0 comments on commit f2d4761

Please sign in to comment.