Fixed #2440 (False negative: basic memory leak)
This commit is contained in:
parent
846d3dae99
commit
09f900ce79
|
@ -587,12 +587,18 @@ void CheckMemoryLeakInFunction::parse_noreturn()
|
||||||
if (indentlevel == 0)
|
if (indentlevel == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (Token::Match(tok2, "[;{}] exit ("))
|
if (Token::Match(tok2->previous(), "[;{}] exit ("))
|
||||||
{
|
{
|
||||||
noreturn.insert(info->className);
|
noreturn.insert(info->className);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function is not a noreturn function
|
||||||
|
if (indentlevel == 0)
|
||||||
|
{
|
||||||
|
notnoreturn.insert(info->className);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -733,7 +739,17 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list<co
|
||||||
// how many parameters is there in the function call?
|
// how many parameters is there in the function call?
|
||||||
int numpar = countParameters(tok);
|
int numpar = countParameters(tok);
|
||||||
if (numpar <= 0)
|
if (numpar <= 0)
|
||||||
|
{
|
||||||
|
// Taking return value => it is not a noreturn function
|
||||||
|
if (tok->strAt(-1) == "=")
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
// Function is not noreturn
|
||||||
|
if (notnoreturn.find(funcname) != notnoreturn.end())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
return (tok->previous()->str() != "=") ? "callfunc" : NULL;
|
return (tok->previous()->str() != "=") ? "callfunc" : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int par = 1;
|
unsigned int par = 1;
|
||||||
unsigned int parlevel = 0;
|
unsigned int parlevel = 0;
|
||||||
|
|
|
@ -349,6 +349,9 @@ public:
|
||||||
/** Function names for functions that are "noreturn" */
|
/** Function names for functions that are "noreturn" */
|
||||||
std::set<std::string> noreturn;
|
std::set<std::string> noreturn;
|
||||||
|
|
||||||
|
/** Function names for functions that are not "noreturn" */
|
||||||
|
std::set<std::string> notnoreturn;
|
||||||
|
|
||||||
SymbolDatabase *symbolDatabase;
|
SymbolDatabase *symbolDatabase;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2619,6 +2619,16 @@ private:
|
||||||
" fatal_error();\n"
|
" fatal_error();\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void fatal_error()\n" // #2440
|
||||||
|
"{ }\n"
|
||||||
|
"\n"
|
||||||
|
"void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" char *p = malloc(100);\n"
|
||||||
|
" fatal_error();\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: p\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue