Skip to content

Commit

Permalink
PCSCCardConnection.__del__: ignore SCARD_E_INVALID_VALUE error
Browse files Browse the repository at this point in the history
In some cases the value self.hcontext becomes invalid before
SCardReleaseContext() is called. This happens if the reader is removed
for example.

The problem was visible when using a smartcard.Session() and we
disconnect the reader before the end of the session. When the program
exists we had something like:

Exception ignored in: <function PCSCCardConnection.__del__ at 0x7f8fb65957e0>
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/pyscard-2.0.3-py3.10-linux-x86_64.egg/smartcard/pcsc/PCSCCardConnection.py", line 90, in __del__
smartcard.Exceptions.CardConnectionException: Failed to release context: Invalid value given.

Thanks to Frank Morgner for the bug report
" Quitting Session causes "Exception ignored in" LudovicRousseau#131 "
LudovicRousseau#131
  • Loading branch information
LudovicRousseau committed May 7, 2022
1 parent b51add1 commit 9bfb915
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion smartcard/pcsc/PCSCCardConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __del__(self):
# can disappear before __del__ is called
self.disconnect()
hresult = SCardReleaseContext(self.hcontext)
if hresult != 0:
if hresult != 0 and hresult != SCARD_E_INVALID_VALUE:
raise CardConnectionException(
'Failed to release context: ' + \
SCardGetErrorMessage(hresult))
Expand Down

0 comments on commit 9bfb915

Please sign in to comment.