[Pcsclite-cvs-commit] PCSC/src winscard_clnt.c,1.11,1.12
rousseau@quantz.debian.org
rousseau@quantz.debian.org
Wed, 03 Sep 2003 23:10:53 +0200
Update of /cvsroot/pcsclite/PCSC/src
In directory quantz:/tmp/cvs-serv2392
Modified Files:
winscard_clnt.c
Log Message:
add SCardUnload() function to free allocated resources. It is mandatory
only if you use dlopen/dlclose to often load/unload the library. Otherwise
you will exhaust the ressources available and get a crash.
Index: winscard_clnt.c
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/winscard_clnt.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- winscard_clnt.c 30 May 2003 15:50:44 -0000 1.11
+++ winscard_clnt.c 3 Sep 2003 21:10:50 -0000 1.12
@@ -148,7 +148,7 @@
i = 0;
pageSize = 0;
- if (phContext == 0)
+ if (phContext == NULL)
return SCARD_E_INVALID_PARAMETER;
else
*phContext = 0;
@@ -158,6 +158,11 @@
*/
if (isExecuted == 0)
{
+ /*
+ * Initialize debug
+ */
+ DebugLogSetLogType(DEBUGLOG_STDERR_DEBUG);
+
g_rgSCardT0Pci.dwProtocol = SCARD_PROTOCOL_T0;
g_rgSCardT1Pci.dwProtocol = SCARD_PROTOCOL_T1;
g_rgSCardRawPci.dwProtocol = SCARD_PROTOCOL_RAW;
@@ -200,7 +205,7 @@
readerStates[i] = (PREADER_STATES)
SYS_PublicMemoryMap(sizeof(READER_STATES),
mapAddr, (i * pageSize));
- if (readerStates[i] == 0)
+ if (readerStates[i] == NULL)
{
DebugLogA("ERROR: Cannot public memory map");
SYS_CloseFile(mapAddr); /* Close the memory map file */
@@ -1962,5 +1967,20 @@
}
else
return SCARD_S_SUCCESS;
+}
+
+/*
+ * free resources allocated by the library
+ * You _shall_ call this function if you use dlopen/dlclose to load/unload the
+ * library. Otherwise you will exhaust the ressources available.
+ */
+void SCardUnload(void)
+{
+ if (!isExecuted)
+ return;
+
+ SHMClientCloseSession();
+ SYS_CloseFile(mapAddr);
+ isExecuted = 0;
}