* 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) {
|
for (const Token* arg : args) {
|
||||||
if (arg->isOp())
|
if (arg->isOp())
|
||||||
continue;
|
continue;
|
||||||
|
if (!(mTokenizer->isCPP() && Token::simpleMatch(arg, "new"))) {
|
||||||
while (arg->astOperand1())
|
while (arg->astOperand1())
|
||||||
arg = arg->astOperand1();
|
arg = arg->astOperand1();
|
||||||
|
}
|
||||||
if (getAllocationType(arg, 0) == No)
|
if (getAllocationType(arg, 0) == No)
|
||||||
continue;
|
continue;
|
||||||
if (isReopenStandardStream(arg))
|
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())))
|
if (closingBrace->str() == "}" && Token::Match(closingBrace->link()->tokAt(-1), "%name%") && (!isNew && precedes(tok, closingBrace->link())))
|
||||||
continue;
|
continue;
|
||||||
returnValueNotUsedError(tok, tok->str());
|
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());
|
returnValueNotUsedError(tok, tok->str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2401,6 +2401,12 @@ private:
|
||||||
" return static_cast<int*>(malloc(size));\n"
|
" return static_cast<int*>(malloc(size));\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void missingAssignment() {
|
||||||
|
@ -2452,7 +2458,7 @@ private:
|
||||||
"{\n"
|
"{\n"
|
||||||
" 42,malloc(42);\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"
|
check("void *f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue