Fixed #7738 (False positive deallocret - delete and return NULL pointer)
This commit is contained in:
parent
d1c66edb03
commit
b5f2fd3c55
|
@ -543,13 +543,14 @@ void CheckLeakAutoVar::functionCall(const Token *tok, VarInfo *varInfo, const Va
|
|||
}
|
||||
|
||||
if (Token::Match(arg, "%var% [-,)] !!.") || Token::Match(arg, "& %var%")) {
|
||||
|
||||
// goto variable
|
||||
if (arg->str() == "&")
|
||||
arg = arg->next();
|
||||
|
||||
bool isnull = arg->hasKnownIntValue() && arg->values.front().intvalue == 0;
|
||||
|
||||
// Is variable allocated?
|
||||
if (!af || af->arg == argNr)
|
||||
if (!isnull && (!af || af->arg == argNr))
|
||||
changeAllocStatus(varInfo, allocation, tok, arg);
|
||||
} else if (Token::Match(arg, "%name% (")) {
|
||||
const Library::AllocFunc* allocFunc = _settings->library.dealloc(arg);
|
||||
|
|
|
@ -304,6 +304,12 @@ private:
|
|||
" return p;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.c:3]: (error) Returning/dereferencing 'p' after it is deallocated / released\n", errout.str());
|
||||
|
||||
check("void f(char *p) {\n"
|
||||
" if (!p) free(p);\n"
|
||||
" return p;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void deallocuse5() { // #4018
|
||||
|
|
Loading…
Reference in New Issue