Skip to content

Commit

Permalink
IFDCloseIFD: Fix a locking issue
Browse files Browse the repository at this point in the history
We should not unlock the mutex of the lock failed.
  • Loading branch information
LudovicRousseau committed May 22, 2024
1 parent c24806f commit 62ca7e8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ifdwrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ RESPONSECODE IFDCloseIFD(READER_CONTEXT * rContext)
{
RESPONSECODE rv;
int repeat;
bool do_unlock = true;

#ifndef PCSCLITE_STATIC_DRIVER
RESPONSECODE(*IFDH_close_channel) (DWORD) = NULL;
Expand All @@ -184,6 +185,9 @@ RESPONSECODE IFDCloseIFD(READER_CONTEXT * rContext)
(void)SYS_USleep(100*1000); /* 100 ms */
goto again;
}
else
/* locking failed but we need to close the IFD */
do_unlock = false;
}

#ifndef PCSCLITE_STATIC_DRIVER
Expand All @@ -193,7 +197,8 @@ RESPONSECODE IFDCloseIFD(READER_CONTEXT * rContext)
#endif

/* END OF LOCKED REGION */
(void)pthread_mutex_unlock(rContext->mMutex);
if (do_unlock)
(void)pthread_mutex_unlock(rContext->mMutex);

return rv;
}
Expand Down

0 comments on commit 62ca7e8

Please sign in to comment.