From edff8d326fa431da983574c757539706e61791d1 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Fri, 12 Dec 2008 19:08:30 +0000 Subject: [PATCH] Memoryleak: fopen and popen report now "Resource leak" instead of "Memory leak" --- CheckMemoryLeak.cpp | 24 ++++++++++++++++-------- CheckMemoryLeak.h | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CheckMemoryLeak.cpp b/CheckMemoryLeak.cpp index 498884729..d57ac3ee0 100644 --- a/CheckMemoryLeak.cpp +++ b/CheckMemoryLeak.cpp @@ -278,10 +278,18 @@ void CheckMemoryLeakClass::MismatchError( const TOKEN *Tok1, const std::listfileLine(tok) << ": Memory leak: " << varname; + errmsg << _tokenizer->fileLine(tok); + + if( alloctype == CheckMemoryLeakClass::FOPEN || + alloctype == CheckMemoryLeakClass::POPEN ) + errmsg << ": Resource leak: "; + else + errmsg << ": Memory leak: "; + + errmsg << varname; _errorLogger->reportErr( errmsg.str() ); } //--------------------------------------------------------------------------- @@ -975,23 +983,23 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const const TOKEN *result; if ( (result = TOKEN::findmatch(tok, "loop alloc ;")) != NULL ) { - MemoryLeak(result, varname); + MemoryLeak(result, varname, alloctype); } else if ( (result = TOKEN::findmatch(tok, "alloc ; if break|continue|return ;")) != NULL ) { // MemoryLeak(Tokenizer::gettok(TOKEN::findmatch(tok, "alloc ; if continue ;"), 3), varname); - MemoryLeak(result->tokAt(3), varname); + MemoryLeak(result->tokAt(3), varname, alloctype); } else if ( _settings._showAll && (result = TOKEN::findmatch(tok, "alloc ; ifv break|continue|return ;")) != NULL ) { - MemoryLeak(result->tokAt(3), varname); + MemoryLeak(result->tokAt(3), varname, alloctype); } else if ( (result = TOKEN::findmatch(tok, "alloc ; alloc|assign|return ;")) != NULL ) { - MemoryLeak(result->tokAt(2), varname); + MemoryLeak(result->tokAt(2), varname, alloctype); } else if ( ! TOKEN::findmatch(tok,"dealloc") && @@ -1001,7 +1009,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_CheckScope( const TOKEN *Tok1, const const TOKEN *last = tok; while (last->next()) last = last->next(); - MemoryLeak(last, varname); + MemoryLeak(last, varname, alloctype); } // detect cases that "simplifycode" don't handle well.. @@ -1242,7 +1250,7 @@ void CheckMemoryLeakClass::CheckMemoryLeak_ClassMembers_Variable( const std::vec if ( Alloc != No && Dealloc == No ) { - MemoryLeak( _tokenizer->tokens(), FullVariableName.str().c_str() ); + MemoryLeak( _tokenizer->tokens(), FullVariableName.str().c_str(), Alloc ); } } diff --git a/CheckMemoryLeak.h b/CheckMemoryLeak.h index fcba393bf..6b520193d 100644 --- a/CheckMemoryLeak.h +++ b/CheckMemoryLeak.h @@ -90,7 +90,7 @@ private: TOKEN *getcode(const TOKEN *tok, std::list callstack, const char varname[], AllocType &alloctype, AllocType &dealloctype); bool notvar(const TOKEN *tok, const char *varnames[]); void instoken(TOKEN *tok, const char str[]); - void MemoryLeak( const TOKEN *tok, const char varname[] ); + void MemoryLeak( const TOKEN *tok, const char varname[], AllocType alloctype ); void MismatchError( const TOKEN *Tok1, const std::list &callstack, const char varname[] ); const char * call_func( const TOKEN *tok, std::list callstack, const char *varnames[], AllocType &alloctype, AllocType &dealloctype ); AllocType GetDeallocationType( const TOKEN *tok, const char *varnames[]);