Fixed #8120 (False positive: Memory pointed to by 'p' is freed twice)
This commit is contained in:
parent
368fa4f54f
commit
4da50942b0
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Reference in New Issue