From 66412ed4aeb90d824713b6537560fae1780d3117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 21 Nov 2008 18:17:40 +0000 Subject: [PATCH] Memory leak: Added checking for 'fopen' and 'popen' --- CheckMemoryLeak.cpp | 18 +++++++++++++++--- CheckMemoryLeak.h | 5 +++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index 8476ab3a0..bff54b06a 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -73,7 +73,7 @@ bool CheckMemoryLeakClass::isclass( const std::string &typestr ) } //--------------------------------------------------------------------------- -AllocType CheckMemoryLeakClass::GetAllocationType( const TOKEN *tok2 ) +CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetAllocationType( const TOKEN *tok2 ) { // What we may have... // * var = (char *)malloc(10); @@ -100,7 +100,7 @@ AllocType CheckMemoryLeakClass::GetAllocationType( const TOKEN *tok2 ) { if ( strcmp(mallocfunc[i], tok2->str) == 0 ) return Malloc; - } + } // Does tok2 point on "malloc", "strdup" or "kmalloc".. const char *gmallocfunc[] = {"g_new", @@ -129,6 +129,12 @@ AllocType CheckMemoryLeakClass::GetAllocationType( const TOKEN *tok2 ) if ( Match( tok2, "new %type% [" ) ) return NewA; + + if ( Match( tok2, "fopen (" ) ) + return FOPEN; + + if ( Match( tok2, "popen (" ) ) + return POPEN; // Userdefined allocation function.. std::list::const_iterator it = listallocfunc.begin(); @@ -142,7 +148,7 @@ AllocType CheckMemoryLeakClass::GetAllocationType( const TOKEN *tok2 ) return No; } -AllocType CheckMemoryLeakClass::GetDeallocationType( const TOKEN *tok, const char *varnames[] ) +CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetDeallocationType( const TOKEN *tok, const char *varnames[] ) { // Redundant condition.. if ( Match(tok, "if ( %var1% )", varnames) ) @@ -166,6 +172,12 @@ AllocType CheckMemoryLeakClass::GetDeallocationType( const TOKEN *tok, const cha if ( Match(tok, "g_free ( %var1% ) ;", varnames) ) return gMalloc; + + if ( Match(tok, "fclose ( %var1% )", varnames) ) + return FOPEN; + + if ( Match(tok, "pclose ( %var1% )", varnames) ) + return POPEN; return No; } diff --git a/CheckMemoryLeak.h b/CheckMemoryLeak.h index ad3df502d..bdf7baeb6 100644 --- a/CheckMemoryLeak.h +++ b/CheckMemoryLeak.h @@ -31,8 +31,6 @@ #include #include -enum AllocType { No, Malloc, gMalloc, New, NewA }; - class CheckMemoryLeakClass { public: @@ -41,6 +39,9 @@ public: void CheckMemoryLeak(); private: + + enum AllocType { No, Malloc, gMalloc, New, NewA, FOPEN, POPEN }; + // Extra allocation.. class AllocFunc {