diff options
author | Jochen Sprickerhof <git@jochen.sprickerhof.de> | 2021-05-16 10:37:25 +0200 |
---|---|---|
committer | Jochen Sprickerhof <git@jochen.sprickerhof.de> | 2021-05-16 10:37:25 +0200 |
commit | 12d0ea062d92a15baee69c4be0e4ae00fcdee416 (patch) | |
tree | 4d40c6b1e509bc8cf29e179ce8473ee74589f580 | |
parent | 0ab68b2d4f6ad0efce45e56df8e94778fe7f758c (diff) | |
download | python-magic-12d0ea062d92a15baee69c4be0e4ae00fcdee416.tar.gz |
Check for cookie attribute before trying to delete it
__del__ is called regardless of whether __init__ passed, so the cookie
attribute may not exits. This can be seen with:
python3 -c "import magic; magic.Magic(foo=None)"
Also discussed in https://github.com/ahupp/python-magic/pull/222#issuecomment-675354824
-rw-r--r-- | magic/__init__.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/magic/__init__.py b/magic/__init__.py index 17456c1..363e88f 100644 --- a/magic/__init__.py +++ b/magic/__init__.py @@ -150,7 +150,7 @@ class Magic: # incorrect fix for a threading problem, however I'm leaving # it in because it's harmless and I'm slightly afraid to # remove it. - if self.cookie and magic_close: + if hasattr(self, 'cookie') and self.cookie and magic_close: magic_close(self.cookie) self.cookie = None |