#2668 fixed memory leak ( freopen() )

This commit is contained in:
Ettl Martin 2011-03-21 15:12:21 +01:00
parent a975301ce4
commit f242cb639e
2 changed files with 50 additions and 2 deletions

View File

@ -48,7 +48,7 @@ static const char * const call_func_white_list[] =
"access", "asctime", "asctime_r", "asprintf", "assert", "atof", "atoi", "atol", "chdir", "chmod", "chown" "access", "asctime", "asctime_r", "asprintf", "assert", "atof", "atoi", "atol", "chdir", "chmod", "chown"
, "clearerr", "ctime", "ctime_r", "delete", "fchmod", "fclose", "fcntl" , "clearerr", "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", "freopen", "fscanf", "fseek"
, "fseeko", "fsetpos", "fstat", "fsync", "ftell", "ftello", "ftruncate" , "fseeko", "fsetpos", "fstat", "fsync", "ftell", "ftello", "ftruncate"
, "fwrite", "getc", "gets", "gmtime", "gmtime_r", "if", "ioctl" , "fwrite", "getc", "gets", "gmtime", "gmtime_r", "if", "ioctl"
, "localtime", "localtime_r" , "localtime", "localtime_r"

View File

@ -229,6 +229,7 @@ private:
TEST_CASE(func19); // Ticket #2056 - if (!f(p)) return 0; TEST_CASE(func19); // Ticket #2056 - if (!f(p)) return 0;
TEST_CASE(func20); // Ticket #2182 - exit is not handled TEST_CASE(func20); // Ticket #2182 - exit is not handled
TEST_CASE(func21); // Ticket #2569 TEST_CASE(func21); // Ticket #2569
TEST_CASE(func22); // Ticket #2668
TEST_CASE(allocfunc1); TEST_CASE(allocfunc1);
TEST_CASE(allocfunc2); TEST_CASE(allocfunc2);
@ -567,7 +568,7 @@ private:
{ {
"access", "asprintf", "atof", "atoi", "atol", "chdir", "chmod", "clearerr", "chown", "delete" "access", "asprintf", "atof", "atoi", "atol", "chdir", "chmod", "clearerr", "chown", "delete"
, "fchmod", "fcntl", "fdatasync", "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets" , "fchmod", "fcntl", "fdatasync", "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets"
, "flock", "for", "fprintf", "fputc", "fputs", "fread", "free", "fscanf", "fseek" , "flock", "for", "fprintf", "fputc", "fputs", "fread", "free", "freopen", "fscanf", "fseek"
, "fseeko", "fsetpos", "fstat", "fsync", "ftell", "ftello", "ftruncate" , "fseeko", "fsetpos", "fstat", "fsync", "ftell", "ftello", "ftruncate"
, "fwrite", "getc", "if", "ioctl", "lockf", "lseek", "memchr", "memcpy" , "fwrite", "getc", "if", "ioctl", "lockf", "lseek", "memchr", "memcpy"
, "memmove", "memset", "posix_fadvise", "posix_fallocate", "pread" , "memmove", "memset", "posix_fadvise", "posix_fallocate", "pread"
@ -2005,6 +2006,53 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
// # 2668
void func22()
{
check("void foo()\n"
"{\n"
" char * cpFile;\n"
" cpFile = new char [13];\n"
" strcpy (cpFile, \"testfile.txt\");\n"
" if(freopen(cpFile,\"w\",stdout)==0)\n"
" {\n"
" return;\n"
" }\n"
" delete [] cpFile;\n"
" fclose (stdout);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:8]: (error) Memory leak: cpFile\n", errout.str());
check("void foo()\n"
"{\n"
" char * cpFile;\n"
" cpFile = new char [13];\n"
" strcpy (cpFile, \"testfile.txt\");\n"
" if(freopen(cpFile,\"w\",stdout)==0)\n"
" {\n"
" delete [] cpFile;\n"
" return;\n"
" }\n"
" fclose (stdout);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:12]: (error) Memory leak: cpFile\n", errout.str());
check("void foo()\n"
"{\n"
" char * cpFile;\n"
" cpFile = new char [13];\n"
" strcpy (cpFile, \"testfile.txt\");\n"
" if(freopen(cpFile,\"w\",stdout)==0)\n"
" {\n"
" delete [] cpFile;\n"
" return;\n"
" }\n"
" delete [] cpFile;\n"
" fclose (stdout);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void allocfunc1() void allocfunc1()
{ {
check("static char *a()\n" check("static char *a()\n"