c3e589
diff -up ./src/configfile.l.coverity ./src/configfile.l
c3e589
--- ./src/configfile.l.coverity	2018-05-23 16:32:54.524430167 -0700
c3e589
+++ ./src/configfile.l	2018-05-23 16:37:23.881925045 -0700
c3e589
@@ -191,9 +191,18 @@ int evaluatetoken(char *pcToken)
c3e589
 		}
c3e589
 		else
c3e589
 		{
c3e589
+			char *new_reader_list;
c3e589
 			reader_list_size++;
c3e589
-			reader_list = realloc(reader_list, reader_list_size *
c3e589
+			new_reader_list = realloc(reader_list, reader_list_size *
c3e589
 				sizeof(SerialReader));
c3e589
+			if (new_reader_list == NULL) {
c3e589
+				free(reader_list);
c3e589
+			}
c3e589
+			reader_list = new_reader_list;
c3e589
+		}
c3e589
+		if (reader_list == NULL) {
c3e589
+			tok_error("No Memory");
c3e589
+			return 1;
c3e589
 		}
c3e589
 
c3e589
 		/* end marker */
c3e589
diff -up ./src/sd-daemon.c.coverity ./src/sd-daemon.c
c3e589
--- ./src/sd-daemon.c.coverity	2018-05-23 16:28:02.571878672 -0700
c3e589
+++ ./src/sd-daemon.c	2018-05-23 16:28:05.080883439 -0700
c3e589
@@ -95,7 +95,7 @@ _sd_export_ int sd_listen_fds(int unset_
c3e589
                 goto finish;
c3e589
         }
c3e589
 
c3e589
-        if (!(e = getenv("LISTEN_FDS"))) {
c3e589
+        if (!(e = secure_getenv("LISTEN_FDS"))) {
c3e589
                 r = 0;
c3e589
                 goto finish;
c3e589
         }
c3e589
diff -up ./src/winscard_clnt.c.coverity ./src/winscard_clnt.c
c3e589
--- ./src/winscard_clnt.c.coverity	2018-05-23 16:42:07.437434512 -0700
c3e589
+++ ./src/winscard_clnt.c	2018-05-23 16:42:10.779440449 -0700
c3e589
@@ -1541,15 +1541,15 @@ retry:
c3e589
 	if (SCARD_AUTOALLOCATE == dwReaderLen)
c3e589
 	{
c3e589
 		dwReaderLen = *pcchReaderLen;
c3e589
-		bufReader = malloc(dwReaderLen);
c3e589
-		if (NULL == bufReader)
c3e589
+		if (NULL == mszReaderName)
c3e589
 		{
c3e589
-			rv = SCARD_E_NO_MEMORY;
c3e589
+			rv = SCARD_E_INVALID_PARAMETER;
c3e589
 			goto end;
c3e589
 		}
c3e589
-		if (NULL == mszReaderName)
c3e589
+		bufReader = malloc(dwReaderLen);
c3e589
+		if (NULL == bufReader)
c3e589
 		{
c3e589
-			rv = SCARD_E_INVALID_PARAMETER;
c3e589
+			rv = SCARD_E_NO_MEMORY;
c3e589
 			goto end;
c3e589
 		}
c3e589
 		*(char **)mszReaderName = bufReader;
c3e589
@@ -1569,15 +1569,15 @@ retry:
c3e589
 	if (SCARD_AUTOALLOCATE == dwAtrLen)
c3e589
 	{
c3e589
 		dwAtrLen = *pcbAtrLen;
c3e589
-		bufAtr = malloc(dwAtrLen);
c3e589
-		if (NULL == bufAtr)
c3e589
+		if (NULL == pbAtr)
c3e589
 		{
c3e589
-			rv = SCARD_E_NO_MEMORY;
c3e589
+			rv = SCARD_E_INVALID_PARAMETER;
c3e589
 			goto end;
c3e589
 		}
c3e589
-		if (NULL == pbAtr)
c3e589
+		bufAtr = malloc(dwAtrLen);
c3e589
+		if (NULL == bufAtr)
c3e589
 		{
c3e589
-			rv = SCARD_E_INVALID_PARAMETER;
c3e589
+			rv = SCARD_E_NO_MEMORY;
c3e589
 			goto end;
c3e589
 		}
c3e589
 		*(LPBYTE *)pbAtr = bufAtr;
c3e589
@@ -3098,15 +3098,15 @@ LONG SCardListReaderGroups(SCARDCONTEXT
c3e589
 
c3e589
 	if (SCARD_AUTOALLOCATE == *pcchGroups)
c3e589
 	{
c3e589
-		buf = malloc(dwGroups);
c3e589
-		if (NULL == buf)
c3e589
+		if (NULL == mszGroups)
c3e589
 		{
c3e589
-			rv = SCARD_E_NO_MEMORY;
c3e589
+			rv = SCARD_E_INVALID_PARAMETER;
c3e589
 			goto end;
c3e589
 		}
c3e589
-		if (NULL == mszGroups)
c3e589
+		buf = malloc(dwGroups);
c3e589
+		if (NULL == buf)
c3e589
 		{
c3e589
-			rv = SCARD_E_INVALID_PARAMETER;
c3e589
+			rv = SCARD_E_NO_MEMORY;
c3e589
 			goto end;
c3e589
 		}
c3e589
 		*(char **)mszGroups = buf;
c3e589
diff -up ./src/winscard_svc.c.coverity ./src/winscard_svc.c
c3e589
--- ./src/winscard_svc.c.coverity	2018-05-23 16:30:31.037160692 -0700
c3e589
+++ ./src/winscard_svc.c	2018-05-23 16:30:35.066168345 -0700
c3e589
@@ -856,7 +856,8 @@ static LONG MSGAddHandle(SCARDCONTEXT hC
c3e589
 					"list_append failed with return value: %d", lrv);
c3e589
 				retval = SCARD_E_NO_MEMORY;
c3e589
 			}
c3e589
-			retval = SCARD_S_SUCCESS;
c3e589
+			else
c3e589
+				retval = SCARD_S_SUCCESS;
c3e589
 		}
c3e589
 
c3e589
 		(void)pthread_mutex_unlock(&threadContext->cardsList_lock);