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...
// * 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<AllocFunc>::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;
}

View File

@ -31,8 +31,6 @@
#include <list>
#include <vector>
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
{