#2667 added open(), _open() and _wopen() function to checkmemoryleak whitelist, incl. unittests;

This commit is contained in:
Ettl Martin 2011-03-21 23:20:46 +01:00
parent 78bcb07e19
commit 38cf9f26df
2 changed files with 102 additions and 3 deletions

View File

@ -45,14 +45,15 @@ CheckMemoryLeakNoVar instance4;
// This list needs to be alphabetically sorted so we can run bsearch on it
static const char * const call_func_white_list[] =
{
"access", "asctime", "asctime_r", "asprintf", "assert", "atof", "atoi", "atol", "chdir", "chmod", "chown"
"_open", "_wopen", "access", "asctime", "asctime_r", "asprintf", "assert"
, "atof", "atoi", "atol", "chdir", "chmod", "chown"
, "clearerr", "ctime", "ctime_r", "delete", "fchmod", "fclose", "fcntl"
, "fdatasync", "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets"
, "flock", "for", "fprintf", "fputc", "fputs", "fread", "free", "freopen", "fscanf", "fseek"
, "fseeko", "fsetpos", "fstat", "fsync", "ftell", "ftello", "ftruncate"
, "fwrite", "getc", "gets", "gmtime", "gmtime_r", "if", "ioctl"
, "localtime", "localtime_r"
, "lockf", "lseek", "lstat", "memchr", "memcmp", "memcpy", "memmove", "memset"
, "lockf", "lseek", "lstat", "memchr", "memcmp", "memcpy", "memmove", "memset", "open"
, "perror", "posix_fadvise", "posix_fallocate", "pread"
, "printf", "puts", "pwrite", "qsort", "read", "readahead", "readdir", "readdir_r", "readv"
, "realloc", "return", "rewind", "rewinddir", "scandir", "scanf", "seekdir"

View File

@ -230,6 +230,7 @@ private:
TEST_CASE(func20); // Ticket #2182 - exit is not handled
TEST_CASE(func21); // Ticket #2569
TEST_CASE(func22); // Ticket #2668
TEST_CASE(func23); // Ticket #2667
TEST_CASE(allocfunc1);
TEST_CASE(allocfunc2);
@ -570,7 +571,7 @@ private:
, "fchmod", "fcntl", "fdatasync", "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets"
, "flock", "for", "fprintf", "fputc", "fputs", "fread", "free", "freopen", "fscanf", "fseek"
, "fseeko", "fsetpos", "fstat", "fsync", "ftell", "ftello", "ftruncate"
, "fwrite", "getc", "if", "ioctl", "lockf", "lseek", "memchr", "memcpy"
, "fwrite", "getc", "if", "ioctl", "lockf", "lseek", "open", "memchr", "memcpy"
, "memmove", "memset", "perror", "posix_fadvise", "posix_fallocate", "pread"
, "printf", "puts", "pwrite", "read", "readahead", "readdir", "readdir_r", "readv"
, "realloc", "return", "rewind", "rewinddir", "scandir", "seekdir"
@ -578,6 +579,7 @@ private:
, "strcat", "strchr", "strcmp", "strcpy", "stricmp", "strlen", "strncat", "strncmp"
, "strncpy", "strrchr", "strstr", "strtod", "strtol", "strtoul", "switch"
, "sync_file_range", "telldir", "typeid", "while", "write", "writev", "lstat", "stat"
, "_open", "_wopen"
};
for (unsigned int i = 0; i < (sizeof(call_func_white_list) / sizeof(char *)); ++i)
@ -2074,6 +2076,102 @@ private:
ASSERT_EQUALS("", errout.str());
}
// # 2667
void func23()
{
// check open() function
// ----------------------
check("int * foo()\n"
"{\n"
" char * cpFile = new char [13];\n"
" strcpy (cpFile, \"testfile.txt\");\n"
" int file=open(cpFile,O_RDONLY);\n"
" if(file < -1)\n"
" {\n"
" return file;\n"
" }\n"
" delete [] cpFile;\n"
" return file;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: cpFile\n", errout.str());
check("int * foo()\n"
"{\n"
" char * cpFile = new char [13];\n"
" strcpy (cpFile, \"testfile.txt\");\n"
" int file=open(cpFile,O_RDONLY);\n"
" if(file < -1)\n"
" {\n"
" delete [] cpFile;\n"
" return file;\n"
" }\n"
" return file;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: cpFile\n", errout.str());
check("int * foo()\n"
"{\n"
" char * cpFile = new char [13];\n"
" strcpy (cpFile, \"testfile.txt\");\n"
" int file=open(cpFile,O_RDONLY);\n"
" if(file < -1)\n"
" {\n"
" delete [] cpFile;\n"
" return file;\n"
" }\n"
" delete [] cpFile;\n"
" return file;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// check for _open, _wopen
// http://msdn.microsoft.com/en-us/library/z0kc8e3z(VS.80).aspx
// -------------------------------------------------------------
check("int * foo()\n"
"{\n"
" char * cpFile = new char [13];\n"
" strcpy (cpFile, \"testfile.txt\");\n"
" int file=_open(cpFile,_O_RDONLY);\n"
" if(file == -1)\n"
" {\n"
" return file;\n"
" }\n"
" delete [] cpFile;\n"
" return file;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: cpFile\n", errout.str());
check("int * foo()\n"
"{\n"
" char * cpFile = new char [13];\n"
" strcpy (cpFile, \"testfile.txt\");\n"
" int file=_open(cpFile,_O_RDONLY);\n"
" if(file == -1)\n"
" {\n"
" delete [] cpFile;\n"
" return file;\n"
" }\n"
" return file;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: cpFile\n", errout.str());
check("int * foo()\n"
"{\n"
" char * cpFile = new char [13];\n"
" strcpy (cpFile, \"testfile.txt\");\n"
" int file=_open(cpFile,_O_RDONLY);\n"
" if(file == -1)\n"
" {\n"
" delete [] cpFile;\n"
" return file;\n"
" }\n"
" delete [] cpFile;\n"
" return file;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void allocfunc1()
{
check("static char *a()\n"