diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 11f3820cc..13b2ea25a 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -2255,7 +2255,8 @@ void CheckMemoryLeakInFunction::checkReallocUsage() --indentlevel; } - if (Token::Match(tok, "%var% = realloc|g_try_realloc ( %var% ,") && + if (tok->varId() > 0 && + Token::Match(tok, "%var% = realloc|g_try_realloc ( %var% ,") && tok->varId() == tok->tokAt(4)->varId() && parameterVarIds.find(tok->varId()) == parameterVarIds.end()) { diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index c911e2cde..4d9e91c98 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -333,6 +333,7 @@ private: TEST_CASE(realloc6); TEST_CASE(realloc7); TEST_CASE(realloc8); + TEST_CASE(realloc9); TEST_CASE(assign); @@ -2059,6 +2060,15 @@ private: ASSERT_EQUALS("", errout.str()); } + void realloc9() + { + check("void foo()\n" + "{\n" + " x = realloc(x,100);\n" + "}\n", false); + ASSERT_EQUALS("", errout.str()); + } + void assign() { check("void foo()\n"