-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix possible memory leak #1487
base: develop
Are you sure you want to change the base?
Fix possible memory leak #1487
Conversation
In `MQTTAsync_receiveThread`, when `pack` is not `NULL` but none of the `if`-`else if`-conditions is fulfilled, `pack` is not freed. To fix this, an `else` block has been added to cleanup the memory of `pack`. Signed-off-by: Harald Reif <[email protected]>
Hello, I have integrated the commit of this pull request into my application. Because I wanted to verify if this fixes my memory leak found by
Unfortunately the memory leak is still there! Valgrind reports also this memory leaks in the context of the paho.mqtt.c library. |
@@ -2320,6 +2320,11 @@ thread_return_type WINAPI MQTTAsync_receiveThread(void* n) | |||
m->c->connected = 0; /* don't send disconnect packet back */ | |||
nextOrClose(m, discrc, "Received disconnect"); | |||
} | |||
else | |||
{ | |||
free(pack); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe, that is not sufficient.
Because pack
points to many different structures.
E.g. if allocated inside MQTTPacket_publish(int MQTTVersion, unsigned char aHeader, char* data, size_t datalen)
pack points to this structure:
/**
* Data for a publish packet.
*/
typedef struct
{
Header header; /**< MQTT header byte */
char* topic; /**< topic string */
int topiclen;
int msgId; /**< MQTT message id */
char* payload; /**< binary payload, length delimited */
int payloadlen; /**< payload length */
int MQTTVersion; /**< the version of MQTT */
MQTTProperties properties; /**< MQTT 5.0 properties. Not used for MQTT < 5.0 */
uint8_t mask[4]; /**< the websockets mask the payload is masked with, if any */
} Publish;
Which includes pointers to other allocated memory, which is not release in this case.
See issue #1518
In
MQTTAsync_receiveThread
, whenpack
is notNULL
but none of theif
-else if
-conditions is fulfilled,pack
is not freed. To fix this, anelse
block has been added to cleanup the memory ofpack
.Signed-off-by: Harald Reif [email protected]