* Fix #10857 FN: leakNoVarFunctionCall * Fix TODO * Fix #10858 FN: leakNoVarFunctionCall (if ( b && malloc ) ) * #11155 FN: leakNoVarFunctionCall (ternary operator)
This commit is contained in:
parent
e7e23e87c2
commit
cdeebc15ea
|
@ -1070,9 +1070,14 @@ 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%|!|,|%oror%|&&")) {
|
} else if (Token::Match(parent, "%comp%|!|,|%oror%|&&|:")) {
|
||||||
if (!(parent->astParent() && parent->str() == ","))
|
if (parent->astParent() && parent->str() == ",")
|
||||||
returnValueNotUsedError(tok, tok->str());
|
continue;
|
||||||
|
if (parent->str() == ":") {
|
||||||
|
if (!(Token::simpleMatch(parent->astParent(), "?") && !parent->astParent()->astParent()))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
returnValueNotUsedError(tok, tok->str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2607,6 +2607,14 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) Return value of allocation function 'malloc' is not stored.\n"
|
ASSERT_EQUALS("[test.cpp:1]: (error) Return value of allocation function 'malloc' is not stored.\n"
|
||||||
"[test.cpp:2]: (error) Return value of allocation function 'malloc' is not stored.\n",
|
"[test.cpp:2]: (error) Return value of allocation function 'malloc' is not stored.\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
|
||||||
|
check("void f0(const bool b) { b ? new int : nullptr; }\n" // #11155
|
||||||
|
"void f1(const bool b) { b ? nullptr : new int; }\n"
|
||||||
|
"int* g0(const bool b) { return b ? new int : nullptr; }\n"
|
||||||
|
"void g1(const bool b) { h(b, b ? nullptr : new int); }\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:1]: (error) Return value of allocation function 'new' is not stored.\n"
|
||||||
|
"[test.cpp:2]: (error) Return value of allocation function 'new' is not stored.\n",
|
||||||
|
errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void smartPointerFunctionParam() {
|
void smartPointerFunctionParam() {
|
||||||
|
|
Loading…
Reference in New Issue