Fixed #5275 (FP mismatchAllocDealloc: user defined opendir()/closedir() on non-POSIX system)
This commit is contained in:
parent
ef3d3f2d40
commit
e13aa0dbc3
|
@ -179,8 +179,11 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
|
|||
if (Token::simpleMatch(tok2, "popen ("))
|
||||
return Pipe;
|
||||
|
||||
if (Token::Match(tok2, "opendir|fdopendir ("))
|
||||
return Dir;
|
||||
if (settings1->standards.posix)
|
||||
{
|
||||
if (Token::Match(tok2, "opendir|fdopendir ("))
|
||||
return Dir;
|
||||
}
|
||||
|
||||
// Does tok2 point on "g_malloc", "g_strdup", ..
|
||||
const int alloctype = settings1->library.alloc(tok2->str());
|
||||
|
|
|
@ -204,6 +204,7 @@ private:
|
|||
TEST_CASE(mismatch4);
|
||||
TEST_CASE(mismatch5);
|
||||
TEST_CASE(mismatch6);
|
||||
TEST_CASE(mismatch7); // opendir()/closedir() on non-POSIX
|
||||
|
||||
TEST_CASE(mismatchSize);
|
||||
|
||||
|
@ -1503,6 +1504,33 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void mismatch7() {
|
||||
Settings settings;
|
||||
settings.standards.posix = false;
|
||||
const char mycode1[]= "DIR *opendir(const char *name);\n"
|
||||
"void closedir(DIR *dir) {\n"
|
||||
" free(dir);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"void f(const char *dir) {\n"
|
||||
" DIR *dirp;\n"
|
||||
" if ((dirp = opendir(dir)) == NULL) return 0;\n"
|
||||
" closedir(dirp);\n"
|
||||
"}\n";
|
||||
check(mycode1, &settings);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
settings.standards.posix = true;
|
||||
check(mycode1, &settings);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
const char mycode2[]= "void f(const char *dir) {\n"
|
||||
" DIR *dirp;\n"
|
||||
" if ((dirp = opendir(dir)) == NULL) return 0;\n"
|
||||
" free(dirp);\n"
|
||||
"}\n";
|
||||
check(mycode2, &settings);
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Mismatching allocation and deallocation: dirp\n", errout.str());
|
||||
}
|
||||
|
||||
void mismatchSize() {
|
||||
check("void f(char *buf)\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue