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

ludovic.rousseau at free.fr ludovic.rousseau at free.fr
Fri Aug 23 08:19:08 UTC 2013


Author: rousseau
Date: 2013-08-23 08:19:08 +0000 (Fri, 23 Aug 2013)
New Revision: 6734

Modified:
   trunk/PCSC/src/winscard_clnt.c
Log:
Fix a memory leak in case of error

When SCARD_AUTOALLOCATE is used we check the parameter is valid and
return in case it is not _before_ calling malloc.

Detected by "clang --analyze"
winscard_clnt.c:1566:9: warning: Potential leak of memory pointed to by 'bufReader'
     rv = SCARD_E_INVALID_PARAMETER;
          ^~~~~~~~~~~~~~~~~~~~~~~~~

winscard_clnt.c:1594:9: warning: Potential leak of memory pointed to by 'bufAtr'
     rv = SCARD_E_INVALID_PARAMETER;
          ^~~~~~~~~~~~~~~~~~~~~~~~~

winscard_clnt.c:3141:9: warning: Potential leak of memory pointed to by 'buf'
      rv = SCARD_E_INVALID_PARAMETER;
           ^~~~~~~~~~~~~~~~~~~~~~~~~


Modified: trunk/PCSC/src/winscard_clnt.c
===================================================================
--- trunk/PCSC/src/winscard_clnt.c	2013-08-22 16:30:34 UTC (rev 6733)
+++ trunk/PCSC/src/winscard_clnt.c	2013-08-23 08:19:08 UTC (rev 6734)
@@ -1555,17 +1555,17 @@
 	if (SCARD_AUTOALLOCATE == dwReaderLen)
 	{
 		dwReaderLen = *pcchReaderLen;
+		if (NULL == mszReaderName)
+		{
+			rv = SCARD_E_INVALID_PARAMETER;
+			goto end;
+		}
 		bufReader = malloc(dwReaderLen);
 		if (NULL == bufReader)
 		{
 			rv = SCARD_E_NO_MEMORY;
 			goto end;
 		}
-		if (NULL == mszReaderName)
-		{
-			rv = SCARD_E_INVALID_PARAMETER;
-			goto end;
-		}
 		*(char **)mszReaderName = bufReader;
 	}
 	else
@@ -1583,17 +1583,17 @@
 	if (SCARD_AUTOALLOCATE == dwAtrLen)
 	{
 		dwAtrLen = *pcbAtrLen;
+		if (NULL == pbAtr)
+		{
+			rv = SCARD_E_INVALID_PARAMETER;
+			goto end;
+		}
 		bufAtr = malloc(dwAtrLen);
 		if (NULL == bufAtr)
 		{
 			rv = SCARD_E_NO_MEMORY;
 			goto end;
 		}
-		if (NULL == pbAtr)
-		{
-			rv = SCARD_E_INVALID_PARAMETER;
-			goto end;
-		}
 		*(LPBYTE *)pbAtr = bufAtr;
 	}
 	else
@@ -3130,17 +3130,17 @@
 
 	if (SCARD_AUTOALLOCATE == *pcchGroups)
 	{
+		if (NULL == mszGroups)
+		{
+			rv = SCARD_E_INVALID_PARAMETER;
+			goto end;
+		}
 		buf = malloc(dwGroups);
 		if (NULL == buf)
 		{
 			rv = SCARD_E_NO_MEMORY;
 			goto end;
 		}
-		if (NULL == mszGroups)
-		{
-			rv = SCARD_E_INVALID_PARAMETER;
-			goto end;
-		}
 		*(char **)mszGroups = buf;
 	}
 	else




More information about the Pcsclite-cvs-commit mailing list