Commit 46d174c4 authored by Ludovic Rousseau's avatar Ludovic Rousseau

MSGRemoveContext(): Do not reset the card if no lock

If the card was not locked (PC/SC transaction) then no need to reset it
when the context is released.
parent c2d79706
......@@ -885,30 +885,38 @@ static LONG MSGRemoveContext(SCARDCONTEXT hContext, SCONTEXT * threadContext)
return rv;
}
if ((rContext->hLockId != 0) && (hCard != rContext->hLockId))
if (0 == rContext->hLockId)
{
/*
* if the card is locked by someone else we do not reset it
* and simulate a card removal
*/
rv = SCARD_W_REMOVED_CARD;
/* no lock. Just leave the card */
(void)SCardDisconnect(hCard, SCARD_LEAVE_CARD);
}
else
{
/* release the lock */
rContext->hLockId = 0;
/*
* We will use SCardStatus to see if the card has been
* reset there is no need to reset each time
* Disconnect is called
*/
rv = SCardStatus(hCard, NULL, NULL, NULL, NULL, NULL, NULL);
if (rv == SCARD_W_RESET_CARD || rv == SCARD_W_REMOVED_CARD)
(void)SCardDisconnect(hCard, SCARD_LEAVE_CARD);
if (hCard != rContext->hLockId)
{
/*
* if the card is locked by someone else we do not reset it
* and simulate a card removal
*/
rv = SCARD_W_REMOVED_CARD;
}
else
(void)SCardDisconnect(hCard, SCARD_RESET_CARD);
{
/* release the lock */
rContext->hLockId = 0;
/*
* We will use SCardStatus to see if the card has been
* reset there is no need to reset each time
* Disconnect is called
*/
rv = SCardStatus(hCard, NULL, NULL, NULL, NULL, NULL, NULL);
if (rv == SCARD_W_RESET_CARD || rv == SCARD_W_REMOVED_CARD)
(void)SCardDisconnect(hCard, SCARD_LEAVE_CARD);
else
(void)SCardDisconnect(hCard, SCARD_RESET_CARD);
}
}
/* Remove entry from the list */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment