diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index e96f524bc..8060bd99f 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -2444,7 +2444,7 @@ void CheckMemoryLeakInFunction::parseFunctionScope(const Token *tok, const Token { const std::string varname(tok2->strAt(3)); const unsigned int varid = tok2->tokAt(3)->varId(); - const unsigned int sz = _tokenizer->sizeOfType(tok->next()); + const unsigned int sz = _tokenizer->sizeOfType(tok2->next()); checkScope(tok->next(), varname, varid, classmember, sz); } } diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index b1a8d3dda..094194f49 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -208,6 +208,8 @@ private: TEST_CASE(mismatch3); TEST_CASE(mismatch4); + TEST_CASE(mismatchSize); + TEST_CASE(func3); TEST_CASE(func4); TEST_CASE(func5); @@ -1359,7 +1361,17 @@ private: ASSERT_EQUALS("[test.cpp:7]: (error) Mismatching allocation and deallocation: p\n", errout.str()); } - + void mismatchSize() + { + check("void f(char *buf)\n" + "{\n" + " int i;\n" + " buf = malloc(3);\n" + " buf[i] = 0;\n" + " free(buf);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } ////////////////////////////////////////////////