Similar to how we do for assignments outside if-statements, bail out since we do not track multiple variables.
This commit is contained in:
parent
19dd59eae6
commit
068e5bad27
|
@ -441,7 +441,8 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
||||||
if (!isLocalVarNoAutoDealloc(innerTok, mTokenizer->isCPP()))
|
if (!isLocalVarNoAutoDealloc(innerTok, mTokenizer->isCPP()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Token::Match(innerTok, "%var% =") && innerTok->astParent() == innerTok->next()) {
|
// Check assignments in the if-statement. Skip multiple assignments since we don't track those
|
||||||
|
if (Token::Match(innerTok, "%var% =") && innerTok->astParent() == innerTok->next() && !innerTok->next()->astParent()->isAssignmentOp()) {
|
||||||
// allocation?
|
// allocation?
|
||||||
// right ast part (after `=` operator)
|
// right ast part (after `=` operator)
|
||||||
const Token* tokRightAstOperand = innerTok->next()->astOperand2();
|
const Token* tokRightAstOperand = innerTok->next()->astOperand2();
|
||||||
|
|
|
@ -164,6 +164,7 @@ private:
|
||||||
TEST_CASE(ifelse22); // #10187
|
TEST_CASE(ifelse22); // #10187
|
||||||
TEST_CASE(ifelse23); // #5473
|
TEST_CASE(ifelse23); // #5473
|
||||||
TEST_CASE(ifelse24); // #1733
|
TEST_CASE(ifelse24); // #1733
|
||||||
|
TEST_CASE(ifelse25); // #9966
|
||||||
|
|
||||||
// switch
|
// switch
|
||||||
TEST_CASE(switch1);
|
TEST_CASE(switch1);
|
||||||
|
@ -1827,6 +1828,17 @@ private:
|
||||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: temp\n", "", errout.str());
|
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: temp\n", "", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ifelse25() { // #9966
|
||||||
|
check("void f() {\n"
|
||||||
|
" void *p, *p2;\n"
|
||||||
|
" if((p2 = p = malloc(10)) == NULL)\n"
|
||||||
|
" return;\n"
|
||||||
|
" (void)p;\n"
|
||||||
|
" free(p2);\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
void switch1() {
|
void switch1() {
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" char *p = 0;\n"
|
" char *p = 0;\n"
|
||||||
|
|
Loading…
Reference in New Issue