* Fix #10857 FN: leakNoVarFunctionCall * Fix TODO
This commit is contained in:
parent
242afc389d
commit
88bf11abba
|
@ -1016,8 +1016,10 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope)
|
|||
for (const Token* arg : args) {
|
||||
if (arg->isOp())
|
||||
continue;
|
||||
if (!(mTokenizer->isCPP() && Token::simpleMatch(arg, "new"))) {
|
||||
while (arg->astOperand1())
|
||||
arg = arg->astOperand1();
|
||||
}
|
||||
if (getAllocationType(arg, 0) == No)
|
||||
continue;
|
||||
if (isReopenStandardStream(arg))
|
||||
|
@ -1068,7 +1070,8 @@ void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope)
|
|||
if (closingBrace->str() == "}" && Token::Match(closingBrace->link()->tokAt(-1), "%name%") && (!isNew && precedes(tok, closingBrace->link())))
|
||||
continue;
|
||||
returnValueNotUsedError(tok, tok->str());
|
||||
} else if (Token::Match(parent, "%comp%|!")) {
|
||||
} else if (Token::Match(parent, "%comp%|!|,")) {
|
||||
if (!(parent->astParent() && parent->str() == ","))
|
||||
returnValueNotUsedError(tok, tok->str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2401,6 +2401,12 @@ private:
|
|||
" return static_cast<int*>(malloc(size));\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void f() { if (new int[42]) {} }\n" // #10857
|
||||
"void g() { if (malloc(42)) {} }\n");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Allocation with new, if doesn't release it.\n"
|
||||
"[test.cpp:2]: (error) Allocation with malloc, if doesn't release it.\n",
|
||||
errout.str());
|
||||
}
|
||||
|
||||
void missingAssignment() {
|
||||
|
@ -2452,7 +2458,7 @@ private:
|
|||
"{\n"
|
||||
" 42,malloc(42);\n"
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Return value of allocation function 'malloc' is not stored.\n", "", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Return value of allocation function 'malloc' is not stored.\n", errout.str());
|
||||
|
||||
check("void *f()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue