diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index fbc2c2008..5b2e6f508 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -188,6 +188,8 @@ static bool isVarUsedInTree(const Token *tok, unsigned int varid) return false; if (tok->varId() == varid) return true; + if (tok->str() == "(" && Token::simpleMatch(tok->astOperand1(), "sizeof")) + return false; return isVarUsedInTree(tok->astOperand1(), varid) || isVarUsedInTree(tok->astOperand2(), varid); } diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index cb8ea5008..62acae14d 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -299,6 +299,18 @@ private: ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: p\n", errout.str()); } + void assign15() { + // #8120 + check("void f() {\n" + " baz *p;\n" + " p = malloc(sizeof *p);\n" + " free(p);\n" + " p = malloc(sizeof *p);\n" + " free(p);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void deallocuse1() { check("void f(char *p) {\n" " free(p);\n"