Memory leak: Added checking for 'fopen' and 'popen'

This commit is contained in:
Daniel Marjamäki 2008-11-21 18:17:40 +00:00
parent a82b46dad6
commit 66412ed4ae
2 changed files with 18 additions and 5 deletions

View File

@ -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... // What we may have...
// * var = (char *)malloc(10); // * var = (char *)malloc(10);
@ -100,7 +100,7 @@ AllocType CheckMemoryLeakClass::GetAllocationType( const TOKEN *tok2 )
{ {
if ( strcmp(mallocfunc[i], tok2->str) == 0 ) if ( strcmp(mallocfunc[i], tok2->str) == 0 )
return Malloc; return Malloc;
} }
// Does tok2 point on "malloc", "strdup" or "kmalloc".. // Does tok2 point on "malloc", "strdup" or "kmalloc"..
const char *gmallocfunc[] = {"g_new", const char *gmallocfunc[] = {"g_new",
@ -129,6 +129,12 @@ AllocType CheckMemoryLeakClass::GetAllocationType( const TOKEN *tok2 )
if ( Match( tok2, "new %type% [" ) ) if ( Match( tok2, "new %type% [" ) )
return NewA; return NewA;
if ( Match( tok2, "fopen (" ) )
return FOPEN;
if ( Match( tok2, "popen (" ) )
return POPEN;
// Userdefined allocation function.. // Userdefined allocation function..
std::list<AllocFunc>::const_iterator it = listallocfunc.begin(); std::list<AllocFunc>::const_iterator it = listallocfunc.begin();
@ -142,7 +148,7 @@ AllocType CheckMemoryLeakClass::GetAllocationType( const TOKEN *tok2 )
return No; return No;
} }
AllocType CheckMemoryLeakClass::GetDeallocationType( const TOKEN *tok, const char *varnames[] ) CheckMemoryLeakClass::AllocType CheckMemoryLeakClass::GetDeallocationType( const TOKEN *tok, const char *varnames[] )
{ {
// Redundant condition.. // Redundant condition..
if ( Match(tok, "if ( %var1% )", varnames) ) 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) ) if ( Match(tok, "g_free ( %var1% ) ;", varnames) )
return gMalloc; return gMalloc;
if ( Match(tok, "fclose ( %var1% )", varnames) )
return FOPEN;
if ( Match(tok, "pclose ( %var1% )", varnames) )
return POPEN;
return No; return No;
} }

View File

@ -31,8 +31,6 @@
#include <list> #include <list>
#include <vector> #include <vector>
enum AllocType { No, Malloc, gMalloc, New, NewA };
class CheckMemoryLeakClass class CheckMemoryLeakClass
{ {
public: public:
@ -41,6 +39,9 @@ public:
void CheckMemoryLeak(); void CheckMemoryLeak();
private: private:
enum AllocType { No, Malloc, gMalloc, New, NewA, FOPEN, POPEN };
// Extra allocation.. // Extra allocation..
class AllocFunc class AllocFunc
{ {