From 47a15b6486076ba05a2ac896e65568943449260b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 20 Jun 2011 18:42:13 +0200 Subject: [PATCH] Fixed #2830 (false positive: resource leak when using fdopen) --- lib/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index f6fbdd87c..dd635e610 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -51,7 +51,7 @@ static const char * const call_func_white_list[] = , "atof", "atoi", "atol", "chdir", "chmod", "chown" , "clearerr", "creat", "ctime", "ctime_r", "delete", "execl", "execle" , "execlp", "execv", "execve", "fchmod", "fclose", "fcntl" - , "fdatasync", "fdopen", "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets" + , "fdatasync", "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets" , "flock", "fmemopen", "fnmatch", "fopen", "fopencookie", "for", "fprintf", "fputc", "fputs", "fread", "free" , "freopen", "fscanf", "fseek", "fseeko", "fsetpos", "fstat", "fsync", "ftell", "ftello" , "ftruncate", "fwrite", "getc", "getenv","getgrnam", "gethostbyaddr", "gethostbyname", "getnetbyname" diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index c603aca93..21342e445 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -315,6 +315,7 @@ private: TEST_CASE(getc_function); TEST_CASE(open_function); + TEST_CASE(open_fdopen); TEST_CASE(creat_function); TEST_CASE(close_function); TEST_CASE(fd_functions); @@ -586,7 +587,7 @@ private: , "_open", "_wopen", "vscanf", "vsscanf", "vfscanf", "vasprintf", "utime", "utimes", "unlink" , "tempnam", "system", "symlink", "strpbrk", "strncasecmp", "strdup", "strcspn", "strcoll" , "setlocale", "sethostname", "rmdir", "rindex", "rename", "remove", "adjtime", "creat", "execle" - , "execl", "execlp", "execve", "execv", "fdopen", "fmemopen", "fnmatch", "fopencookie", "fopen" + , "execl", "execlp", "execve", "execv", "fmemopen", "fnmatch", "fopencookie", "fopen" , "getgrnam", "gethostbyaddr", "getnetbyname", "getopt", "getopt_long", "getprotobyname", "getpwnam" , "getservbyname", "getservbyport", "glob", "index", "inet_addr", "inet_aton", "inet_network" , "initgroups", "link", "mblen", "mbstowcs", "mbtowc", "mkdir", "mkfifo", "mknod", "obstack_printf" @@ -3343,6 +3344,18 @@ private: ASSERT_EQUALS("", errout.str()); } + void open_fdopen() + { + // Ticket #2830 + check("void f(const char *path)\n" + "{\n" + " int fd = open(path, O_RDONLY);\n" + " FILE *f = fdopen(fd, x);\n" + " fclose(f);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } + void creat_function() { check("void f(const char *path)\n"