Also, in the tests, change socket/close to resource to get error messages which say "resource leak" instead of "memory leak".
This commit is contained in:
parent
438584a49e
commit
42a41e8b41
|
@ -316,6 +316,9 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
|||
if (!tok || tok == endToken)
|
||||
break;
|
||||
|
||||
if (Token::Match(tok, "const %type%"))
|
||||
tok = tok->tokAt(2);
|
||||
|
||||
// parse statement, skip to last member
|
||||
const Token *varTok = tok;
|
||||
while (Token::Match(varTok, "%name% ::|. %name% !!("))
|
||||
|
|
|
@ -41,7 +41,7 @@ private:
|
|||
settings.library.setalloc("malloc", id, -1);
|
||||
settings.library.setrealloc("realloc", id, -1);
|
||||
settings.library.setdealloc("free", id, 1);
|
||||
while (!Library::ismemory(++id));
|
||||
while (!Library::isresource(++id));
|
||||
settings.library.setalloc("socket", id, -1);
|
||||
settings.library.setdealloc("close", id, 1);
|
||||
while (!Library::isresource(++id));
|
||||
|
@ -81,6 +81,7 @@ private:
|
|||
TEST_CASE(assign19);
|
||||
TEST_CASE(assign20); // #9187
|
||||
TEST_CASE(assign21); // #10186
|
||||
TEST_CASE(assign22); // #9139
|
||||
|
||||
TEST_CASE(isAutoDealloc);
|
||||
|
||||
|
@ -438,6 +439,18 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void assign22() { // #9139
|
||||
check("void f(char tempFileName[256]) {\n"
|
||||
" const int fd = socket(AF_INET, SOCK_PACKET, 0 );\n"
|
||||
"}", true);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Resource leak: fd\n", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" const void * const p = malloc(10);\n"
|
||||
"}", true);
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Memory leak: p\n", errout.str());
|
||||
}
|
||||
|
||||
void isAutoDealloc() {
|
||||
check("void f() {\n"
|
||||
" char *p = new char[100];"
|
||||
|
|
Loading…
Reference in New Issue