Skip to content

Commit

Permalink
Fix invalid copy of null mosquitto_auth_opt
Browse files Browse the repository at this point in the history
This also makes clang-analyzer stop complaining about a use after free
that didn't exist, in my opinion.
  • Loading branch information
halfgaar committed Apr 5, 2023
1 parent 7f80000 commit 08bbe0a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mosquittoauthoptcompatwrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,20 @@ mosquitto_auth_opt::~mosquitto_auth_opt()
mosquitto_auth_opt &mosquitto_auth_opt::operator=(const mosquitto_auth_opt &other)
{
if (key)
{
delete key;
key = nullptr;
}
if (value)
{
delete value;
value = nullptr;
}

this->key = strdup(other.key);
this->value = strdup(other.value);
if (other.key)
this->key = strdup(other.key);
if (other.value)
this->value = strdup(other.value);

return *this;
}
Expand Down

0 comments on commit 08bbe0a

Please sign in to comment.