Fix some Coverity defects

This commit is contained in:
Ian Craggs 2020-04-16 12:22:44 +01:00
parent 2f9641a38f
commit 644c4d4d6c
4 changed files with 23 additions and 19 deletions

View File

@ -2350,12 +2350,14 @@ MQTTResponse MQTTClient_publish5(MQTTClient handle, const char* topicName, int p
*deliveryToken = msg->msgid;
exit_and_free:
if (p->topic)
free(p->topic);
if (p->payload)
free(p->payload);
if (p)
{
if (p->topic)
free(p->topic);
if (p->payload)
free(p->payload);
free(p);
}
if (rc == SOCKET_ERROR)
{

View File

@ -243,10 +243,10 @@ exit:
int pstget(void* handle, char* key, char** buffer, int* buflen)
{
int rc = 0;
FILE *fp;
FILE *fp = NULL;
char *clientDir = handle;
char *file;
char *buf;
char *file = NULL;
char *buf = NULL;
unsigned long fileLen = 0;
unsigned long bytesRead = 0;
@ -274,7 +274,6 @@ int pstget(void* handle, char* key, char** buffer, int* buflen)
fseek(fp, 0, SEEK_SET);
if ((buf = (char *)malloc(fileLen)) == NULL)
{
free(file);
rc = PAHO_MEMORY_ERROR;
goto exit;
}
@ -283,15 +282,15 @@ int pstget(void* handle, char* key, char** buffer, int* buflen)
*buflen = bytesRead;
if ( bytesRead != fileLen )
rc = MQTTCLIENT_PERSISTENCE_ERROR;
fclose(fp);
fp = NULL;
} else
rc = MQTTCLIENT_PERSISTENCE_ERROR;
free(file);
/* the caller must free buf */
exit:
if (file)
free(file);
if (fp)
fclose(fp);
FUNC_EXIT_RC(rc);
return rc;
}
@ -456,7 +455,7 @@ int containskeyUnix(char *dirname, char *key)
{
int notFound = MQTTCLIENT_PERSISTENCE_ERROR;
char *filekey, *ptraux;
DIR *dp;
DIR *dp = NULL;
struct dirent *dir_entry;
struct stat stat_info;
@ -491,10 +490,11 @@ int containskeyUnix(char *dirname, char *key)
free(filekey);
}
}
closedir(dp);
}
exit:
if (dp)
closedir(dp);
FUNC_EXIT_RC(notFound);
return notFound;
}
@ -730,7 +730,7 @@ int keysUnix(char *dirname, char ***keys, int *nkeys)
int nfkeys = 0;
char *ptraux;
int i;
DIR *dp;
DIR *dp = NULL;
struct dirent *dir_entry;
struct stat stat_info;
@ -753,6 +753,7 @@ int keysUnix(char *dirname, char ***keys, int *nkeys)
free(temp);
}
closedir(dp);
dp = NULL;
} else
{
rc = MQTTCLIENT_PERSISTENCE_ERROR;
@ -799,7 +800,6 @@ int keysUnix(char *dirname, char ***keys, int *nkeys)
}
free(temp);
}
closedir(dp);
} else
{
rc = MQTTCLIENT_PERSISTENCE_ERROR;
@ -812,6 +812,8 @@ int keysUnix(char *dirname, char ***keys, int *nkeys)
/* the caller must free keys */
exit:
if (dp)
closedir(dp);
FUNC_EXIT_RC(rc);
return rc;
}

View File

@ -981,7 +981,7 @@ int SSLSocket_putdatas(SSL* ssl, int socket, char* buf0, size_t buf0len, int cou
SSL_unlock_mutex(&sslCoreMutex);
goto exit;
}
Log(TRACE_MIN, -1, "Partial write: incomplete write of %d bytes on SSL socket %d",
Log(TRACE_MIN, -1, "Partial write: incomplete write of %lu bytes on SSL socket %d",
iovec.iov_len, socket);
SocketBuffer_pendingWrite(socket, ssl, 1, &iovec, &free, iovec.iov_len, 0);
*sockmem = socket;

View File

@ -1220,7 +1220,7 @@ int WebSocket_upgrade( networkHandles *net )
rc = TCPSOCKET_INTERRUPTED;
read_buf = WebSocket_getRawSocketData( net, 12u, &rcv );
if (read_buf && rcv < 12u) {
if ((read_buf == NULL) || rcv < 12u) {
Log(TRACE_PROTOCOL, 1, "WebSocket upgrade read not complete %lu", rcv );
goto exit;
}
@ -1244,7 +1244,7 @@ int WebSocket_upgrade( networkHandles *net )
/* Did we read the whole response? */
if (read_buf && rcv > 4 && memcmp(&read_buf[rcv-4], "\r\n\r\n", 4) != 0)
{
Log(TRACE_PROTOCOL, -1, "WebSocket HTTP upgrade response read not complete %d", rcv);
Log(TRACE_PROTOCOL, -1, "WebSocket HTTP upgrade response read not complete %lu", rcv);
rc = SOCKET_ERROR;
goto exit;
}