[Pcsclite-cvs-commit] r6443 - /trunk/PCSC/src/winscard_svc.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Fri Aug 24 07:59:58 UTC 2012


Author: rousseau
Date: Fri Aug 24 07:59:57 2012
New Revision: 6443

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=6443
Log:
MSGAddHandle(): Add mutex lock/unlock around cardsList list

A lock/unlock pair of mutex was missing.

Thanks to Dmitry Torokhov <dtor at vmware.com> for the patch

Modified:
    trunk/PCSC/src/winscard_svc.c

Modified: trunk/PCSC/src/winscard_svc.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_svc.c?rev=6443&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_svc.c (original)
+++ trunk/PCSC/src/winscard_svc.c Fri Aug 24 07:59:57 2012
@@ -825,12 +825,16 @@
 static LONG MSGAddHandle(SCARDCONTEXT hContext, SCARDHANDLE hCard,
 	SCONTEXT * threadContext)
 {
+	LONG retval = SCARD_E_INVALID_VALUE;
+
 	if (threadContext->hContext == hContext)
 	{
 		/*
 		 * Find an empty spot to put the hCard value
 		 */
 		int listLength, lrv;
+
+		(void)pthread_mutex_lock(&threadContext->cardsList_lock);
 
 		listLength = list_size(&(threadContext->cardsList));
 		if (listLength >= contextMaxCardHandles)
@@ -839,22 +843,24 @@
 				"Too many card handles for thread context @%p: %d (max is %d)"
 				"Restart pcscd with --max-card-handle-per-thread value",
 				threadContext, listLength, contextMaxCardHandles);
-			return SCARD_E_NO_MEMORY;
+			retval = SCARD_E_NO_MEMORY;
 		}
-
-		(void)pthread_mutex_lock(&threadContext->cardsList_lock);
-		lrv = list_append(&(threadContext->cardsList), &hCard);
+		else
+		{
+			lrv = list_append(&(threadContext->cardsList), &hCard);
+			if (lrv < 0)
+			{
+				Log2(PCSC_LOG_CRITICAL,
+					"list_append failed with return value: %d", lrv);
+				retval = SCARD_E_NO_MEMORY;
+			}
+			retval = SCARD_S_SUCCESS;
+		}
+
 		(void)pthread_mutex_unlock(&threadContext->cardsList_lock);
-		if (lrv < 0)
-		{
-			Log2(PCSC_LOG_CRITICAL, "list_append failed with return value: %d",
-				lrv);
-			return SCARD_E_NO_MEMORY;
-		}
-		return SCARD_S_SUCCESS;
-	}
-
-	return SCARD_E_INVALID_VALUE;
+	}
+
+	return retval;
 }
 
 static LONG MSGRemoveHandle(SCARDHANDLE hCard, SCONTEXT * threadContext)




More information about the Pcsclite-cvs-commit mailing list