diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index dd39e63f2..81f87bd60 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -45,7 +45,7 @@ CheckMemoryLeakNoVar instance4; // This list needs to be alphabetically sorted so we can run bsearch on it 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" , "fdatasync", "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets" , "flock", "for", "fprintf", "fputc", "fputs", "fread", "free", "fscanf", "fseek" diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 4f8512138..85b61c638 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -565,7 +565,7 @@ private: 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" , "flock", "for", "fprintf", "fputc", "fputs", "fread", "free", "fscanf", "fseek" , "fseeko", "fsetpos", "fstat", "fsync", "ftell", "ftello", "ftruncate" @@ -1823,6 +1823,52 @@ private: " return;\n" "}\n"); 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()