Fix #9438 (Don't warn for return (void*) malloc(1)) (#2307)

This commit is contained in:
Rikard Falkeborn 2019-10-30 17:55:47 +01:00 committed by Daniel Marjamäki
parent 277c59e5f3
commit 239b660a52
2 changed files with 12 additions and 1 deletions

View File

@ -999,7 +999,8 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope)
if ((mTokenizer->isCPP() && functionName == "delete") ||
functionName == "free" ||
functionName == "fclose" ||
functionName == "realloc")
functionName == "realloc" ||
functionName == "return")
continue;
if (!CheckMemoryLeakInFunction::test_white_list(functionName, mSettings, mTokenizer->isCPP()))

View File

@ -2171,6 +2171,16 @@ private:
"}");
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());
check("void* f(int size) {\n"
" return (void*) malloc(size);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("int* f(int size) {\n"
" return static_cast<int*>(malloc(size));\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void missingAssignment() {