diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 064e2fe81..dd39e63f2 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -56,7 +56,7 @@ static const char * const call_func_white_list[] = , "posix_fadvise", "posix_fallocate", "pread" , "printf", "puts", "pwrite", "qsort", "read", "readahead", "readdir", "readdir_r", "readv" , "realloc", "return", "rewind", "rewinddir", "scandir", "scanf", "seekdir" - , "setbuf", "setbuffer", "setlinebuf", "setvbuf", "snprintf", "sprintf", "sscanf", "strcasecmp" + , "setbuf", "setbuffer", "setlinebuf", "setvbuf", "snprintf", "sprintf", "sscanf", "stat", "strcasecmp" , "strcat", "strchr", "strcmp", "strcpy", "stricmp", "strlen", "strncat", "strncmp" , "strncpy", "strrchr", "strstr", "strtod", "strtol", "strtoul", "switch" , "sync_file_range", "telldir", "time", "typeid", "vfprintf", "vprintf" diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index e08559841..4f8512138 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -576,7 +576,7 @@ private: , "setbuf", "setbuffer", "setlinebuf", "setvbuf", "snprintf", "sprintf", "strcasecmp" , "strcat", "strchr", "strcmp", "strcpy", "stricmp", "strlen", "strncat", "strncmp" , "strncpy", "strrchr", "strstr", "strtod", "strtol", "strtoul", "switch" - , "sync_file_range", "telldir", "typeid", "while", "write", "writev", "lstat" + , "sync_file_range", "telldir", "typeid", "while", "write", "writev", "lstat", "stat" }; for (unsigned int i = 0; i < (sizeof(call_func_white_list) / sizeof(char *)); ++i) @@ -1735,6 +1735,8 @@ private: //# Ticket 2569 void func21() { + // checking for lstat function: + // ---------------------------- check("void foo ()\n" "{\n" " struct stat CFileAttr;\n" @@ -1776,6 +1778,51 @@ private: " return;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + + /// checking for stat function: + // ---------------------------- + check("void foo ()\n" + "{\n" + " struct stat CFileAttr;\n" + " char *cpFile = new char [13];\n" + " strcpy (cpFile, \"testfile.txt\");\n" + " if ( stat (cpFile, &CFileAttr) != 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 ( stat (cpFile, &CFileAttr) != 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 ( stat (cpFile, &CFileAttr) != 0)\n" + " {\n" + " delete [] cpFile;\n" + " return;\n" + " }\n" + " delete [] cpFile;\n" + " return;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void allocfunc1()