leakNoReturnVar: Don't break early (#2095)
There seems to be no reason for stopping checking the scope if a call to free() is seen (or fclose() or realloc()), so just continue checking. Also, if there are multiple arguments, check all, perhaps there are more memory leaks to warn about.
This commit is contained in:
parent
c0a8d628b9
commit
fd3cb24973
|
@ -1000,7 +1000,7 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope)
|
||||||
functionName == "free" ||
|
functionName == "free" ||
|
||||||
functionName == "fclose" ||
|
functionName == "fclose" ||
|
||||||
functionName == "realloc")
|
functionName == "realloc")
|
||||||
break;
|
continue;
|
||||||
|
|
||||||
if (!CheckMemoryLeakInFunction::test_white_list(functionName, mSettings, mTokenizer->isCPP()))
|
if (!CheckMemoryLeakInFunction::test_white_list(functionName, mSettings, mTokenizer->isCPP()))
|
||||||
continue;
|
continue;
|
||||||
|
@ -1016,7 +1016,6 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope)
|
||||||
if (isReopenStandardStream(arg))
|
if (isReopenStandardStream(arg))
|
||||||
continue;
|
continue;
|
||||||
functionCallLeak(arg, arg->str(), functionName);
|
functionCallLeak(arg, arg->str(), functionName);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2159,6 +2159,18 @@ private:
|
||||||
" return ret;\n"
|
" return ret;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f() {\n"
|
||||||
|
" free(malloc(1));\n"
|
||||||
|
" strcpy(a, strdup(p));\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:3]: (error) Allocation with strdup, strcpy doesn't release it.\n", errout.str());
|
||||||
|
|
||||||
|
check("void f() {\n"
|
||||||
|
" memcmp(calloc(10, 10), strdup(q), 100);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:2]: (error) Allocation with calloc, memcmp doesn't release it.\n"
|
||||||
|
"[test.cpp:2]: (error) Allocation with strdup, memcmp doesn't release it.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void missingAssignment() {
|
void missingAssignment() {
|
||||||
|
|
Loading…
Reference in New Issue