[Pcsclite-git-commit] [PCSC] 04/06: Client side: add and use SCardGetContextValidity()
Ludovic Rousseau
rousseau at moszumanska.debian.org
Fri Jan 27 20:40:56 UTC 2017
This is an automated email from the git hooks/post-receive script.
rousseau pushed a commit to branch master
in repository PCSC.
commit ccfcd6e75ba9ccb5da02e18e5af909d8ec5f146a
Author: Ludovic Rousseau <ludovic.rousseau at free.fr>
Date: Fri Jan 27 10:36:02 2017 +0100
Client side: add and use SCardGetContextValidity()
SCardGetContextValidity(hContext) returns a boolean and does not take
any lock.
It is similar to SCardGetAndLockContext(hContext, FALSE)
Thanks to Maksim Ivanov for the idea
"[Pcsclite-muscle] Data races related to SCardCancel"
http://lists.alioth.debian.org/pipermail/pcsclite-muscle/Week-of-Mon-20170116/000789.html
---
src/winscard_clnt.c | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/src/winscard_clnt.c b/src/winscard_clnt.c
index 98fe61d..a638642 100644
--- a/src/winscard_clnt.c
+++ b/src/winscard_clnt.c
@@ -408,6 +408,26 @@ inline static LONG SCardUnlockThread(void)
return pthread_mutex_unlock(&clientMutex);
}
+/**
+ * @brief Tell if a context index from the Application Context vector \c
+ * _psContextMap is valid or not.
+ *
+ * @param[in] hContext Application Context whose index will be find.
+ *
+ * @return \c TRUE if the context exists
+ * @return \c FALSE if the context does not exist
+ */
+static int SCardGetContextValidity(SCARDCONTEXT hContext)
+{
+ SCONTEXTMAP * currentContextMap;
+
+ (void)SCardLockThread();
+ currentContextMap = SCardGetContextTH(hContext);
+ (void)SCardUnlockThread();
+
+ return currentContextMap != NULL;
+}
+
static LONG SCardEstablishContextTH(DWORD, LPCVOID, LPCVOID,
/*@out@*/ LPSCARDCONTEXT);
@@ -2908,15 +2928,13 @@ end:
LONG SCardFreeMemory(SCARDCONTEXT hContext, LPCVOID pvMem)
{
LONG rv = SCARD_S_SUCCESS;
- SCONTEXTMAP * currentContextMap;
PROFILE_START
/*
* Make sure this context has been opened
*/
- currentContextMap = SCardGetAndLockContext(hContext, FALSE);
- if (NULL == currentContextMap)
+ if (! SCardGetContextValidity(hContext))
return SCARD_E_INVALID_HANDLE;
free((void *)pvMem);
@@ -3157,7 +3175,6 @@ error:
LONG SCardIsValidContext(SCARDCONTEXT hContext)
{
LONG rv;
- SCONTEXTMAP * currentContextMap;
PROFILE_START
API_TRACE_IN("%ld", hContext)
@@ -3167,8 +3184,7 @@ LONG SCardIsValidContext(SCARDCONTEXT hContext)
/*
* Make sure this context has been opened
*/
- currentContextMap = SCardGetAndLockContext(hContext, FALSE);
- if (currentContextMap == NULL)
+ if (! SCardGetContextValidity(hContext))
rv = SCARD_E_INVALID_HANDLE;
PROFILE_END(rv)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pcsclite/PCSC.git
More information about the Pcsclite-cvs-commit
mailing list