Fixed #8120 (False positive: Memory pointed to by 'p' is freed twice)

This commit is contained in:
Daniel Marjamäki 2019-05-30 16:22:41 +02:00
parent 368fa4f54f
commit 4da50942b0
2 changed files with 14 additions and 0 deletions

View File

@ -188,6 +188,8 @@ static bool isVarUsedInTree(const Token *tok, unsigned int varid)
return false; return false;
if (tok->varId() == varid) if (tok->varId() == varid)
return true; return true;
if (tok->str() == "(" && Token::simpleMatch(tok->astOperand1(), "sizeof"))
return false;
return isVarUsedInTree(tok->astOperand1(), varid) || isVarUsedInTree(tok->astOperand2(), varid); return isVarUsedInTree(tok->astOperand1(), varid) || isVarUsedInTree(tok->astOperand2(), varid);
} }

View File

@ -299,6 +299,18 @@ private:
ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: p\n", errout.str()); 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() { void deallocuse1() {
check("void f(char *p) {\n" check("void f(char *p) {\n"
" free(p);\n" " free(p);\n"