Fixed #4540 (memory leak not detected ('.' or '->' is used before Function))

This commit is contained in:
Daniel Marjamäki 2013-01-31 17:00:50 +01:00
parent ec1c86c152
commit bd7e3cbac5
2 changed files with 12 additions and 3 deletions

View File

@ -140,7 +140,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
if (! tok2->isName())
return No;
if (!Token::Match(tok2, "%type% :: %type%")) {
if (!Token::Match(tok2, "%type%|%var% ::|. %type%")) {
// Does tok2 point on "malloc", "strdup" or "kmalloc"..
static const char * const mallocfunc[] = {
"malloc",
@ -215,7 +215,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
}
while (Token::Match(tok2,"%type% :: %type%"))
while (Token::Match(tok2,"%type%|%var% ::|. %type%"))
tok2 = tok2->tokAt(2);
// User function

View File

@ -241,7 +241,7 @@ private:
TEST_CASE(allocfunc10);
TEST_CASE(allocfunc11);
TEST_CASE(allocfunc12); // #3660: allocating and returning non-local pointer => not allocfunc
TEST_CASE(allocfunc13); // Ticket #4494 - class function
TEST_CASE(allocfunc13); // Ticket #4494 and #4540 - class function
TEST_CASE(throw1);
TEST_CASE(throw2);
@ -2594,6 +2594,15 @@ private:
" char *x = n::a();\n"
"}");
ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: x\n", errout.str());
check("class C {\n" // ¤4540
" char *a() { return malloc(100); }\n"
"}\n"
"void b() {\n"
" C c;"
" char *x = c.a();\n"
"}");
ASSERT_EQUALS("[test.cpp:6]: (error) Memory leak: x\n", errout.str());
}
void throw1() {