Eric Sesterhenn: Fixed #1032 (False positive resource leak with exit at end of function)
This commit is contained in:
parent
96268b4caf
commit
48bb1fdc83
|
@ -1795,6 +1795,20 @@ const Token *CheckMemoryLeakInFunction::findleak(const Token *tokens, bool all)
|
|||
const Token *last = tokens;
|
||||
while (last->next())
|
||||
last = last->next();
|
||||
|
||||
// check if we call exit before the end of the funcion
|
||||
Token *tok2 = last->previous();
|
||||
if (tok2)
|
||||
{
|
||||
if (Token::simpleMatch(tok2, ";")) {
|
||||
const Token *tok3 = tok2->previous();
|
||||
if (tok3 && Token::simpleMatch(tok3, "exit"))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
|
|
|
@ -2078,6 +2078,25 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void exit6()
|
||||
{
|
||||
check("int main(int argc, char *argv[]) {\n"
|
||||
" FILE *sfile;\n"
|
||||
" unsigned long line;\n"
|
||||
" sfile = fopen(\"bar\", \"r\");\n"
|
||||
" if (!sfile)\n"
|
||||
" return 1;\n"
|
||||
" for(line = 0; ; line++) {\n"
|
||||
" if (argc > 3)\n"
|
||||
" break;\n"
|
||||
" exit(0);\n"
|
||||
" }\n"
|
||||
" fclose(sfile);\n"
|
||||
" exit(0);\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void noreturn()
|
||||
{
|
||||
check("void fatal_error()\n"
|
||||
|
|
Loading…
Reference in New Issue