diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index bf9c67f13..d96680b18 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -627,9 +627,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::liststr() == ";") addtoken(";"); - if (varid && - (Token::Match(tok->previous(), "[(;{}] %varid% =", varid) || - Token::Match(tok, "asprintf ( & %varid% ,", varid))) + if (Token::Match(tok->previous(), "[(;{}] %varid% =", varid) || + Token::Match(tok, "asprintf ( & %varid% ,", varid)) { AllocType alloc; @@ -1782,6 +1781,10 @@ void CheckMemoryLeakInFunction::check() if (tok->next()->str() == "static") continue; + // return/else is not part of a variable declaration.. + if (Token::Match(tok->next(), "return|else")) + continue; + if (Token::Match(tok, "[{};] %type% * const| %var% [;=]")) { const Token *vartok = tok->tokAt(tok->tokAt(3)->str() != "const" ? 3 : 4);