Set username and password fields to NULL if not used #1227

This commit is contained in:
Ian Craggs 2022-05-20 13:26:34 +01:00
parent e72f39ffba
commit f54f10ec10
2 changed files with 12 additions and 0 deletions

View File

@ -804,11 +804,17 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options)
#endif
if (m->c->username)
{
free((void*)m->c->username);
m->c->username = NULL;
}
if (options->username)
m->c->username = MQTTStrdup(options->username);
if (m->c->password)
{
free((void*)m->c->password);
m->c->password = NULL;
}
if (options->password)
{
m->c->password = MQTTStrdup(options->password);

View File

@ -1625,11 +1625,17 @@ static MQTTResponse MQTTClient_connectURI(MQTTClient handle, MQTTClient_connectO
#endif
if (m->c->username)
{
free((void*)m->c->username);
m->c->username = NULL;
}
if (options->username)
m->c->username = MQTTStrdup(options->username);
if (m->c->password)
{
free((void*)m->c->password);
m->c->password = NULL;
}
if (options->password)
{
m->c->password = MQTTStrdup(options->password);