Fixed #1912 (False positive: memory leak (calling noreturn function))
This commit is contained in:
parent
2e2baa23a6
commit
694325d51f
|
@ -2032,21 +2032,9 @@ const Token *CheckMemoryLeakInFunction::findleak(const Token *tokens)
|
||||||
while (last->next())
|
while (last->next())
|
||||||
last = last->next();
|
last = last->next();
|
||||||
|
|
||||||
// check if we call exit before the end of the funcion
|
// not a leak if exit is called before the end of the funcion
|
||||||
Token *tok2 = last->previous();
|
if (!Token::Match(last->tokAt(-2), "exit|callfunc ; }"))
|
||||||
if (tok2)
|
return last;
|
||||||
{
|
|
||||||
if (Token::simpleMatch(tok2, ";"))
|
|
||||||
{
|
|
||||||
const Token *tok3 = tok2->previous();
|
|
||||||
if (tok3 && Token::simpleMatch(tok3, "exit"))
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return last;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -356,7 +356,6 @@ private:
|
||||||
// Calls to unknown functions.. they may throw exception, quit the program, etc
|
// Calls to unknown functions.. they may throw exception, quit the program, etc
|
||||||
TEST_CASE(unknownFunction1);
|
TEST_CASE(unknownFunction1);
|
||||||
TEST_CASE(unknownFunction2);
|
TEST_CASE(unknownFunction2);
|
||||||
TEST_CASE(unknownFunction3);
|
|
||||||
TEST_CASE(unknownFunction4);
|
TEST_CASE(unknownFunction4);
|
||||||
TEST_CASE(unknownFunction5);
|
TEST_CASE(unknownFunction5);
|
||||||
|
|
||||||
|
@ -805,6 +804,9 @@ private:
|
||||||
ASSERT_EQUALS(notfound, dofindleak("; loop { alloc ; if break; } dealloc ;"));
|
ASSERT_EQUALS(notfound, dofindleak("; loop { alloc ; if break; } dealloc ;"));
|
||||||
ASSERT_EQUALS(1, dofindleak("; loop alloc ;"));
|
ASSERT_EQUALS(1, dofindleak("; loop alloc ;"));
|
||||||
ASSERT_EQUALS(1, dofindleak("; loop alloc ; dealloc ;"));
|
ASSERT_EQUALS(1, dofindleak("; loop alloc ; dealloc ;"));
|
||||||
|
|
||||||
|
// callfunc (might be noreturn)
|
||||||
|
ASSERT_EQUALS(notfound, dofindleak("; alloc ; callfunc ; }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2296,16 +2298,6 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: p\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Memory leak: p\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void unknownFunction3()
|
|
||||||
{
|
|
||||||
check("void foo()\n"
|
|
||||||
"{\n"
|
|
||||||
" int *p = new int[100];\n"
|
|
||||||
" ThrowException();\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Memory leak: p\n", errout.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void unknownFunction4()
|
void unknownFunction4()
|
||||||
{
|
{
|
||||||
check("void foo()\n"
|
check("void foo()\n"
|
||||||
|
|
Loading…
Reference in New Issue