Skip to content

Commit 16972c2

Browse files
authored
Fix bug in Magic when destructor called too early
Potentially `magic_open` may fail, and when python attempts to gc the Magic instance it fails with: ``` Exception ignored in: <function Magic.__del__ at 0x7f595ba06430> Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/magic.py", line 129, in __del__ if self.cookie and magic_close: AttributeError: 'Magic' object has no attribute 'cookie' ```
1 parent 1a9f90a commit 16972c2

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

magic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def __init__(self, mime=False, magic_file=None, mime_encoding=False,
4848
uncompress - Try to look inside compressed files.
4949
raw - Do not try to decode "non-printable" chars.
5050
"""
51+
52+
self.cookie = None
5153
self.flags = MAGIC_NONE
5254
if mime:
5355
self.flags |= MAGIC_MIME_TYPE

0 commit comments

Comments
 (0)