From 0c6352a826de0f7e250d810740278f58e27a5287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 29 May 2010 21:56:18 +0200 Subject: [PATCH] Memory leaks: small fixes. add checking of 'g_fopen'. don't let 'fclose' calls be interpreted as 'callfunc' --- lib/checkmemoryleak.cpp | 4 ++-- test/testmemleak.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 87ff60dcd..62f9e94d0 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -44,7 +44,7 @@ CheckMemoryLeakStructMember instance3; static const char * const call_func_white_list[] = { "asctime", "asctime_r", "asprintf", "atof", "atoi", "atol", "clearerr" - , "ctime", "ctime_r", "delete", "fchmod", "fcntl" + , "ctime", "ctime_r", "delete", "fchmod", "fclose", "fcntl" , "fdatasync", "feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets" , "flock", "for", "fprintf", "fputc", "fputs", "fread", "free", "fscanf", "fseek" , "fseeko", "fsetpos", "fstat", "fsync", "ftell", "ftello", "ftruncate" @@ -148,7 +148,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2, Token::Match(tok2, "new ( nothrow ) %type% [")) return NewArray; - if (Token::Match(tok2, "fopen|tmpfile (")) + if (Token::Match(tok2, "fopen|tmpfile|g_fopen (")) return File; if (Token::Match(tok2, "open|openat|creat|mkstemp|mkostemp (")) diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 71ee94f6a..ff4482bf2 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -452,6 +452,7 @@ private: ASSERT_EQUALS(";;dealloc;", getcode("char *s; delete [] (s);", "s")); ASSERT_EQUALS(";;dealloc;", getcode("void *p; foo(fclose(p));", "p")); ASSERT_EQUALS(";;dealloc;", getcode("void *p; foo(close(p));", "p")); + ASSERT_EQUALS(";;;;", getcode("FILE *f1; FILE *f2; fclose(f1);", "f2")); // if.. ASSERT_EQUALS(";;if{}", getcode("char *s; if (a) { }", "s"));