Double free: Improved handling of noreturn functions. Partial revert of previous fix.

This commit is contained in:
Daniel Marjamäki 2014-05-04 13:11:21 +02:00
parent 636a15ac55
commit 42b85088c5
2 changed files with 11 additions and 22 deletions

View File

@ -168,14 +168,6 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
if (tok->str() == "(" && tok->previous()->isName()) { if (tok->str() == "(" && tok->previous()->isName()) {
functionCall(tok->previous(), varInfo, NOALLOC); functionCall(tok->previous(), varInfo, NOALLOC);
tok = tok->link(); tok = tok->link();
if (Token::simpleMatch(tok,") ; }")) {
bool unknown = false;
const bool noreturn = _tokenizer->IsScopeNoReturn(tok->tokAt(2), &unknown);
if (noreturn)
varInfo->clear();
}
continue; continue;
} }
@ -361,15 +353,12 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
if (dealloc == NOALLOC && Token::simpleMatch(tok, ") ; }")) { if (dealloc == NOALLOC && Token::simpleMatch(tok, ") ; }")) {
const std::string &functionName(tok->link()->previous()->str()); const std::string &functionName(tok->link()->previous()->str());
bool unknown = false; bool unknown = false;
if (_settings->library.leakignore.find(functionName) == _settings->library.leakignore.end() && if (_tokenizer->IsScopeNoReturn(tok->tokAt(2), &unknown)) {
_settings->library.use.find(functionName) == _settings->library.use.end() && if (!unknown)
_tokenizer->IsScopeNoReturn(tok->tokAt(2), &unknown)) {
if (unknown) {
//const std::string &functionName(tok->link()->previous()->str());
varInfo->possibleUsageAll(functionName);
} else {
varInfo->clear(); varInfo->clear();
} else if (_settings->library.leakignore.find(functionName) == _settings->library.leakignore.end() &&
_settings->library.use.find(functionName) == _settings->library.use.end())
varInfo->possibleUsageAll(functionName);
} }
} }

View File

@ -350,9 +350,9 @@ private:
} }
void doublefree4() { // #5451 - exit void doublefree4() { // #5451 - exit
check("void foo(char *p) {\n" check("void f(char *p) {\n"
" if (x) {\n" " if (x) {\n"
" free(p)\n" " free(p);\n"
" exit(1);\n" " exit(1);\n"
" }\n" " }\n"
" free(p);\n" " free(p);\n"