CheckMemoryLeak: Fix fp for allocation function that returns success value
This commit is contained in:
parent
b3c2ea2c4f
commit
f94243f85e
|
@ -464,6 +464,9 @@ const char *CheckMemoryLeak::functionArgAlloc(const Function *func, unsigned int
|
||||||
if (!func || !func->functionScope)
|
if (!func || !func->functionScope)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
|
if (!Token::simpleMatch(func->retDef, "void"))
|
||||||
|
return "";
|
||||||
|
|
||||||
std::list<Variable>::const_iterator arg = func->argumentList.begin();
|
std::list<Variable>::const_iterator arg = func->argumentList.begin();
|
||||||
for (; arg != func->argumentList.end(); ++arg) {
|
for (; arg != func->argumentList.end(); ++arg) {
|
||||||
if (arg->index() == targetpar-1)
|
if (arg->index() == targetpar-1)
|
||||||
|
|
|
@ -2666,6 +2666,20 @@ private:
|
||||||
" free(tmp);\n"
|
" free(tmp);\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("int alloc(char **str) {\n"
|
||||||
|
" *str = malloc(20);\n"
|
||||||
|
" if (condition) { free(str); return -123; }\n"
|
||||||
|
" return 0;\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"void bar()\n"
|
||||||
|
"{\n"
|
||||||
|
" char *p;\n"
|
||||||
|
" if ((ret = alloc(&p)) != 0) return;\n"
|
||||||
|
" free(p);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS(std::string(""), errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue