diff --git a/CMakeLists.txt b/CMakeLists.txt index c52a42e4a83e06ef2c6d77f488e0105f2c71a147..a290730fe15025eb642efa3867db9212a12f9ec9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,6 @@ file(READ version.minor PAHO_VERSION_MINOR) file(READ version.patch PAHO_VERSION_PATCH) SET(CLIENT_VERSION ${PAHO_VERSION_MAJOR}.${PAHO_VERSION_MINOR}.${PAHO_VERSION_PATCH}) -ENABLE_LANGUAGE(CXX) INCLUDE(GNUInstallDirs) STRING(TIMESTAMP BUILD_TIMESTAMP UTC) diff --git a/src/Clients.h b/src/Clients.h index 2c6fa8ba1bf4f03694d7ae6e695f2f5eb26955dc..43f1aea9eff98018a02b897367d87b73a4d0dd02 100644 --- a/src/Clients.h +++ b/src/Clients.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2019 IBM Corp. + * Copyright (c) 2009, 2020 IBM Corp. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 @@ -124,24 +124,24 @@ typedef struct unsigned int good : 1; /**< if we have an error on the socket we turn this off */ unsigned int ping_outstanding : 1; signed int connect_state : 4; - networkHandles net; - int msgID; - int keepAliveInterval; + networkHandles net; /**< network info for this client */ + int msgID; /**< the MQTT message id */ + int keepAliveInterval; /**< the MQTT keep alive interval */ int retryInterval; - int maxInflightMessages; - willMessages* will; - List* inboundMsgs; - List* outboundMsgs; /**< in flight */ - List* messageQueue; + int maxInflightMessages; /**< the max number of inflight outbound messages we allow */ + willMessages* will; /**< the MQTT will message, if any */ + List* inboundMsgs; /**< inbound in flight messages */ + List* outboundMsgs; /**< outbound in flight messages */ + List* messageQueue; /**< inbound complete but undelivered messages */ unsigned int qentry_seqno; - void* phandle; /* the persistence handle */ - MQTTClient_persistence* persistence; /* a persistence implementation */ + void* phandle; /**< the persistence handle */ + MQTTClient_persistence* persistence; /**< a persistence implementation */ void* context; /* calling context - used when calling disconnect_internal */ - int MQTTVersion; - int sessionExpiry; /**< MQTT 5 session expiry */ + int MQTTVersion; /**< the version of MQTT being used, 3, 4 or 5 */ + int sessionExpiry; /**< MQTT 5 session expiry */ #if defined(OPENSSL) - MQTTClient_SSLOptions *sslopts; - SSL_SESSION* session; /***< SSL session pointer for fast handhake */ + MQTTClient_SSLOptions *sslopts; /**< the SSL/TLS connect options */ + SSL_SESSION* session; /**< SSL session pointer for fast handhake */ #endif } Clients; diff --git a/src/Heap.c b/src/Heap.c index 7e4588c928241ca2e5af7bf3aeceae99d5e3285d..5caee598971860b54a88f813cf5993dba1c2b223 100644 --- a/src/Heap.c +++ b/src/Heap.c @@ -160,13 +160,14 @@ void* mymalloc(char* file, int line, size_t size) storageElement* s = NULL; size_t space = sizeof(storageElement); size_t filenamelen = strlen(file)+1; + void* rc = NULL; Thread_lock_mutex(heap_mutex); size = Heap_roundup(size); if ((s = malloc(sizeof(storageElement))) == NULL) { Log(LOG_ERROR, 13, errmsg); - return NULL; + goto exit; } memset(s, 0, sizeof(storageElement)); @@ -175,7 +176,7 @@ void* mymalloc(char* file, int line, size_t size) { Log(LOG_ERROR, 13, errmsg); free(s); - return NULL; + goto exit; } memset(s->file, 0, sizeof(filenamelen)); @@ -188,7 +189,7 @@ void* mymalloc(char* file, int line, size_t size) Log(LOG_ERROR, 13, errmsg); free(s->file); free(s); - return NULL; + goto exit; } memset(s->stack, 0, sizeof(filenamelen)); StackTrace_get(Thread_getid(), s->stack, STACK_LEN); @@ -200,7 +201,7 @@ void* mymalloc(char* file, int line, size_t size) Log(LOG_ERROR, 13, errmsg); free(s->file); free(s); - return NULL; + goto exit; } memset(s->ptr, 0, size + 2*sizeof(eyecatcherType)); space += size + 2*sizeof(eyecatcherType); @@ -211,8 +212,10 @@ void* mymalloc(char* file, int line, size_t size) state.current_size += size; if (state.current_size > state.max_size) state.max_size = state.current_size; + rc = ((eyecatcherType*)(s->ptr)) + 1; /* skip start eyecatcher */ +exit: Thread_unlock_mutex(heap_mutex); - return ((eyecatcherType*)(s->ptr)) + 1; /* skip start eyecatcher */ + return rc; } @@ -336,7 +339,7 @@ void *myrealloc(char* file, int line, void* p, size_t size) if ((s->ptr = realloc(s->ptr, size + 2*sizeof(eyecatcherType))) == NULL) { Log(LOG_ERROR, 13, errmsg); - return NULL; + goto exit; } space += size + 2*sizeof(eyecatcherType) - s->size; *(eyecatcherType*)(s->ptr) = eyecatcher; /* start eyecatcher */ @@ -350,6 +353,7 @@ void *myrealloc(char* file, int line, void* p, size_t size) rc = s->ptr; TreeAdd(&heap, s, space); } +exit: Thread_unlock_mutex(heap_mutex); return (rc == NULL) ? NULL : ((eyecatcherType*)(rc)) + 1; /* skip start eyecatcher */ } diff --git a/src/MQTTAsync.c b/src/MQTTAsync.c index 5fc26ed83ac81a4191aac0378bd8b72c2ae75c7f..a67fbe9710b28dda3049e3829be417363cef1031 100644 --- a/src/MQTTAsync.c +++ b/src/MQTTAsync.c @@ -3472,6 +3472,7 @@ static int MQTTAsync_assignMsgId(MQTTAsyncs* m) msgid = (msgid == MAX_MSG_ID) ? 1 : msgid + 1; while (ListFindItem(commands, &msgid, cmdMessageIDCompare) || + ListFindItem(m->c->outboundMsgs, &msgid, messageIDCompare) || ListFindItem(m->responses, &msgid, cmdMessageIDCompare)) { msgid = (msgid == MAX_MSG_ID) ? 1 : msgid + 1; @@ -3785,12 +3786,15 @@ int MQTTAsync_send(MQTTAsync handle, const char* destinationName, int payloadlen } if ((pub->command.details.pub.destinationName = MQTTStrdup(destinationName)) == NULL) { + free(pub); rc = PAHO_MEMORY_ERROR; goto exit; } pub->command.details.pub.payloadlen = payloadlen; if ((pub->command.details.pub.payload = malloc(payloadlen)) == NULL) { + free(pub->command.details.pub.destinationName); + free(pub); rc = PAHO_MEMORY_ERROR; goto exit; } diff --git a/src/WebSocket.c b/src/WebSocket.c index 58f385abe919e5982dd41451cdc5cead22278c67..d116ccebd957f83605c50198e8c587fbdd4106e9 100644 --- a/src/WebSocket.c +++ b/src/WebSocket.c @@ -345,12 +345,14 @@ static void WebSocket_unmaskData(uint8_t *mask, size_t idx, int count, char** bu { int i; + FUNC_ENTRY; for (i = 0; i < count; ++i) { size_t j; for ( j = 0u; j < buflens[i]; ++j, ++idx ) buffers[i][j] ^= mask[idx % 4]; } + FUNC_EXIT; } @@ -912,9 +914,12 @@ int WebSocket_putdatas(networkHandles* net, char** buf0, size_t* buf0len, #endif rc = Socket_putdatas(net->socket, wsdata.wsbuf0, wsdata.wsbuf0len, count, buffers, buflens, freeData); - if (mask_data) - WebSocket_unmaskData(wsdata.mask, *buf0len, count, buffers, buflens); - free(wsdata.wsbuf0); /* free temporary ws header */ + if (rc != TCPSOCKET_INTERRUPTED) + { + if (mask_data) + WebSocket_unmaskData(wsdata.mask, *buf0len, count, buffers, buflens); + free(wsdata.wsbuf0); /* free temporary ws header */ + } } else { @@ -1259,7 +1264,7 @@ int WebSocket_upgrade( networkHandles *net ) goto exit; } - if ( rcv > 0 && strncmp( read_buf, "HTTP/1.1", 8u ) == 0 ) + if (strncmp( read_buf, "HTTP/1.1", 8u ) == 0) { if (strncmp( &read_buf[9], "101", 3u ) != 0) { @@ -1269,7 +1274,7 @@ int WebSocket_upgrade( networkHandles *net ) } } - if ( rcv > 0 && strncmp( read_buf, "HTTP/1.1 101", 12u ) == 0 ) + if (strncmp( read_buf, "HTTP/1.1 101", 12u ) == 0) { const char *p;