diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 65eac6a33..730aad85c 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1438,15 +1438,17 @@ bool CheckClass::hasAllocation(const Function *func, const Scope* scope) const return true; // check for deallocating memory - const Token *var = nullptr; + const Token *var; if (Token::Match(tok, "free ( %var%")) var = tok->tokAt(2); else if (Token::Match(tok, "delete [ ] %var%")) var = tok->tokAt(3); else if (Token::Match(tok, "delete %var%")) var = tok->next(); + else + continue; // Check for assignment to the deleted pointer (only if its a member of the class) - if (var && isMemberVar(scope, var)) { + if (isMemberVar(scope, var)) { for (const Token *tok1 = var->next(); tok1 && (tok1 != last); tok1 = tok1->next()) { if (Token::Match(tok1, "%varid% =", var->varId())) return true;