[Pcsclite-cvs-commit] r6703 - trunk/PCSC/src

ludovic.rousseau at free.fr ludovic.rousseau at free.fr
Thu Aug 1 09:25:47 UTC 2013


Author: rousseau
Date: 2013-08-01 09:25:47 +0000 (Thu, 01 Aug 2013)
New Revision: 6703

Modified:
   trunk/PCSC/src/configfile.l
Log:
Fix memory leaks

Free the malloc-ed strings.

The strings are only allocated _once_ when the config files in
/etc/reader.conf.d/ are parsed. This is not really a problem unless you
embedd pcscd in another process and do init/deinit pcscd without exiting
the process (as maybe used on Android or iOS).

Thanks to Alan Kozlay for the patch


Modified: trunk/PCSC/src/configfile.l
===================================================================
--- trunk/PCSC/src/configfile.l	2013-07-31 17:16:54 UTC (rev 6702)
+++ trunk/PCSC/src/configfile.l	2013-08-01 09:25:47 UTC (rev 6703)
@@ -28,7 +28,7 @@
 static char *pcPrevious;
 static char *pcCurrent;
 static char *pcFriendlyname;
-static const char *pcDevicename;
+static char *pcDevicename;
 static char *pcLibpath;
 static char *pcChannelid;
 static int badError;
@@ -182,6 +182,7 @@
 		pcLibpath != NULL && pcChannelid != NULL && badError != 1)
 	{
 		int channelId;
+		static char* defaultDeviceName = "";
 
 		if (0 == reader_list_size)
 		{
@@ -201,7 +202,7 @@
 
 		/* the DEVICENAME parameter is optional */
 		if (NULL == pcDevicename)
-			pcDevicename = "";
+			pcDevicename = defaultDeviceName;
 
 		channelId = strtoul(pcChannelid, NULL, 0);
 		reader_list[reader_list_size-2].pcFriendlyname = strdup(pcFriendlyname);
@@ -209,9 +210,17 @@
 		reader_list[reader_list_size-2].pcLibpath = strdup(pcLibpath),
 		reader_list[reader_list_size-2].channelId = channelId;
 
+		free(pcFriendlyname);
 		pcFriendlyname = NULL;
+
+		if (pcDevicename != defaultDeviceName)
+			free(pcDevicename);
 		pcDevicename = NULL;
+
+		free(pcLibpath);
 		pcLibpath = NULL;
+
+		free(pcChannelid);
 		pcChannelid = NULL;
 	}
 




More information about the Pcsclite-cvs-commit mailing list