Skip to content

Commit d8e64b4

Browse files
Fix FP leakNoVarFunctionCall (#4243)
* Fix #10857 FN: leakNoVarFunctionCall * Fix TODO * Fix #10858 FN: leakNoVarFunctionCall (if ( b && malloc ) ) * #11155 FN: leakNoVarFunctionCall (ternary operator) * Fix #11157 FN: leakNoVarFunctionCall (switch condition) * Fix FN constStatement * Fix FP leakNoVarFunctionCall * Fix FP leakNoVarFunctionCall * Format * Fix FP leakNoVarFunctionCall with unknown function * Fix FP leakNoVarFunctionCall
1 parent 06b408e commit d8e64b4

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

lib/checkmemoryleak.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,8 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope)
10111011
functionName == "return")
10121012
continue;
10131013

1014+
if (Token::simpleMatch(tok->next()->astParent(), "(")) // passed to another function
1015+
continue;
10141016
if (!tok->isKeyword() && mSettings->library.isNotLibraryFunction(tok))
10151017
continue;
10161018
if (!CheckMemoryLeakInFunction::test_white_list(functionName, mSettings, mTokenizer->isCPP()))

test/testmemleak.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2417,7 +2417,7 @@ class TestMemleakNoVar : public TestFixture {
24172417
ASSERT_EQUALS("", errout.str());
24182418

24192419
check("struct S {\n"
2420-
" static void load(const QString & projPath) {\n"
2420+
" static void load(const QString& projPath) {\n"
24212421
" if (proj_)\n"
24222422
" return;\n"
24232423
" proj_ = new ProjectT(projPath);\n"
@@ -2427,6 +2427,12 @@ class TestMemleakNoVar : public TestFixture {
24272427
" static Core::ProjectBase* proj_;\n"
24282428
"};\n");
24292429
ASSERT_EQUALS("", errout.str());
2430+
2431+
check("void f(const std::string& s, int n) {\n"
2432+
" std::unique_ptr<char[]> u;\n"
2433+
" u.reset(strcpy(new char[n], s.c_str()));\n"
2434+
"};\n");
2435+
ASSERT_EQUALS("", errout.str());
24302436
}
24312437

24322438
void missingAssignment() {

0 commit comments

Comments
 (0)