#2659 added access()-function to checkmemoryleak white-list and provided untittests.

This commit is contained in:
Ettl Martin 2011-03-20 23:39:44 +01:00
parent 3407561df6
commit 01249d4f48
2 changed files with 48 additions and 2 deletions

View File

@ -45,7 +45,7 @@ CheckMemoryLeakNoVar instance4;
// This list needs to be alphabetically sorted so we can run bsearch on it // This list needs to be alphabetically sorted so we can run bsearch on it
static const char * const call_func_white_list[] = static const char * const call_func_white_list[] =
{ {
"asctime", "asctime_r", "asprintf", "assert", "atof", "atoi", "atol", "clearerr" "access", "asctime", "asctime_r", "asprintf", "assert", "atof", "atoi", "atol", "clearerr"
, "ctime", "ctime_r", "delete", "fchmod", "fclose", "fcntl" , "ctime", "ctime_r", "delete", "fchmod", "fclose", "fcntl"
, "fdatasync", "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets" , "fdatasync", "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets"
, "flock", "for", "fprintf", "fputc", "fputs", "fread", "free", "fscanf", "fseek" , "flock", "for", "fprintf", "fputc", "fputs", "fread", "free", "fscanf", "fseek"

View File

@ -565,7 +565,7 @@ private:
static const char * const call_func_white_list[] = static const char * const call_func_white_list[] =
{ {
"asprintf", "atof", "atoi", "atol", "clearerr", "delete", "fchmod", "fcntl" "access", "asprintf", "atof", "atoi", "atol", "clearerr", "delete", "fchmod", "fcntl"
, "fdatasync", "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets" , "fdatasync", "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets"
, "flock", "for", "fprintf", "fputc", "fputs", "fread", "free", "fscanf", "fseek" , "flock", "for", "fprintf", "fputc", "fputs", "fread", "free", "fscanf", "fseek"
, "fseeko", "fsetpos", "fstat", "fsync", "ftell", "ftello", "ftruncate" , "fseeko", "fsetpos", "fstat", "fsync", "ftell", "ftello", "ftruncate"
@ -1823,6 +1823,52 @@ private:
" return;\n" " return;\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// checking for access function
// http://www.gnu.org/s/libc/manual/html_node/Testing-File-Access.html
// --------------------------------------------------------------------
check("void foo ()\n"
"{\n"
" struct stat CFileAttr;\n"
" char *cpFile = new char [13];\n"
" strcpy (cpFile, \"testfile.txt\");\n"
" if ( access (cpFile, R_OK) != 0)\n"
" {\n"
" return;\n"
" }\n"
" return;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:10]: (error) Memory leak: cpFile\n", errout.str());
check("void foo ()\n"
"{\n"
" struct stat CFileAttr;\n"
" char *cpFile = new char [13];\n"
" strcpy (cpFile, \"testfile.txt\");\n"
" if (access (cpFile, R_OK) != 0)\n"
" {\n"
" delete [] cpFile;\n"
" return;\n"
" }\n"
" return;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:11]: (error) Memory leak: cpFile\n", errout.str());
check("void foo ()\n"
"{\n"
" struct stat CFileAttr;\n"
" char *cpFile = new char [13];\n"
" strcpy (cpFile, \"testfile.txt\");\n"
" if (access (cpFile, R_OK) != 0)\n"
" {\n"
" delete [] cpFile;\n"
" return;\n"
" }\n"
" delete [] cpFile;\n"
" return;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void allocfunc1() void allocfunc1()