From ab6888dbfec62189ad1577cd10d21352af5077a7 Mon Sep 17 00:00:00 2001 From: Ettl Martin Date: Sun, 20 Mar 2011 21:52:25 +0100 Subject: [PATCH] fixed ticket 2659: added lstat function to white list; provided unit-tests. --- lib/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 46 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 92c60ace8..064e2fe81 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -52,7 +52,7 @@ static const char * const call_func_white_list[] = , "fseeko", "fsetpos", "fstat", "fsync", "ftell", "ftello", "ftruncate" , "fwrite", "getc", "gets", "gmtime", "gmtime_r", "if", "ioctl" , "localtime", "localtime_r" - , "lockf", "lseek", "memchr", "memcmp", "memcpy", "memmove", "memset" + , "lockf", "lseek", "lstat", "memchr", "memcmp", "memcpy", "memmove", "memset" , "posix_fadvise", "posix_fallocate", "pread" , "printf", "puts", "pwrite", "qsort", "read", "readahead", "readdir", "readdir_r", "readv" , "realloc", "return", "rewind", "rewinddir", "scandir", "scanf", "seekdir" diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index c549b57b2..e08559841 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -228,6 +228,7 @@ private: TEST_CASE(func18); TEST_CASE(func19); // Ticket #2056 - if (!f(p)) return 0; TEST_CASE(func20); // Ticket #2182 - exit is not handled + TEST_CASE(func21); // Ticket #2569 TEST_CASE(allocfunc1); TEST_CASE(allocfunc2); @@ -575,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" + , "sync_file_range", "telldir", "typeid", "while", "write", "writev", "lstat" }; for (unsigned int i = 0; i < (sizeof(call_func_white_list) / sizeof(char *)); ++i) @@ -1731,8 +1732,51 @@ private: ASSERT_EQUALS("", errout.str()); } + //# Ticket 2569 + void func21() + { + check("void foo ()\n" + "{\n" + " struct stat CFileAttr;\n" + " char *cpFile = new char [13];\n" + " strcpy (cpFile, \"testfile.txt\");\n" + " if (lstat (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 (lstat (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 (lstat (cpFile, &CFileAttr) != 0)\n" + " {\n" + " delete [] cpFile;\n" + " return;\n" + " }\n" + " delete [] cpFile;\n" + " return;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } void allocfunc1() {