From 08bbe0a49d1210328903f8e7ecd010fbf3d7d921 Mon Sep 17 00:00:00 2001 From: Wiebe Cazemier Date: Wed, 5 Apr 2023 09:58:20 +1000 Subject: [PATCH] Fix invalid copy of null mosquitto_auth_opt This also makes clang-analyzer stop complaining about a use after free that didn't exist, in my opinion. --- mosquittoauthoptcompatwrap.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mosquittoauthoptcompatwrap.cpp b/mosquittoauthoptcompatwrap.cpp index 425b2154..28c04540 100644 --- a/mosquittoauthoptcompatwrap.cpp +++ b/mosquittoauthoptcompatwrap.cpp @@ -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; }