memleakOnRealloc: Don't warn if pointer is NULL in condition
This commit is contained in:
parent
3880412c46
commit
da8ad9ce19
|
@ -550,6 +550,11 @@ void CheckMemoryLeakInFunction::checkReallocUsage()
|
|||
Token::findmatch(scope->bodyStart, "[{};] %varid% = *| %name% .| %name%| [;=]", tok, tok->varId()))
|
||||
continue;
|
||||
|
||||
// Check if the argument is known to be null, which means it is not a memory leak
|
||||
if (arg->hasKnownIntValue() && arg->getKnownIntValue() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const Token* tokEndRealloc = reallocTok->linkAt(1);
|
||||
// Check that the allocation isn't followed immediately by an 'if (!var) { error(); }' that might handle failure
|
||||
if (Token::simpleMatch(tokEndRealloc->next(), "; if (") &&
|
||||
|
|
|
@ -201,7 +201,7 @@ private:
|
|||
" free(a);\n"
|
||||
"}");
|
||||
|
||||
TODO_ASSERT_EQUALS("", "[test.cpp:4]: (error) Common realloc mistake: 'a' nulled but not freed upon failure\n", errout.str());
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void realloc4() {
|
||||
|
@ -296,7 +296,7 @@ private:
|
|||
" return;\n"
|
||||
" free(a);\n"
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("", "[test.cpp:4]: (error) Common realloc mistake: 'a' nulled but not freed upon failure\n", errout.str());
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void realloc13() {
|
||||
|
|
Loading…
Reference in New Issue