Eric Sesterhenn: Fixed #1032 (False positive resource leak with exit at end of function)

This commit is contained in:
Daniel Marjamäki 2009-12-03 19:19:20 +01:00
parent 96268b4caf
commit 48bb1fdc83
2 changed files with 33 additions and 0 deletions

View File

@ -1795,6 +1795,20 @@ const Token *CheckMemoryLeakInFunction::findleak(const Token *tokens, bool all)
const Token *last = tokens; const Token *last = tokens;
while (last->next()) while (last->next())
last = 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; return last;
} }

View File

@ -2078,6 +2078,25 @@ private:
ASSERT_EQUALS("", errout.str()); 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() void noreturn()
{ {
check("void fatal_error()\n" check("void fatal_error()\n"