From 671ef01f427bc8de286612ecb704692f7e489d73 Mon Sep 17 00:00:00 2001 From: Jay Sigbrandt Date: Wed, 26 Nov 2014 08:28:19 +0100 Subject: [PATCH] Make Valgrind happy This version compiles on Solaris x86 and SPARC and does not SEGV. On Solaris, there will be a 40 bytes of reachable memory on exit. On other platforms all reachable memory will be freed. Under Linux (Ubuntu 12.04) "valgrind --leak-check=full cppcheck" says: HEAP SUMMARY: in use at exit: 0 bytes in 0 blocks total heap usage: 461 allocs, 461 frees, 41,015 bytes allocated All heap blocks were freed -- no leaks are possible --- lib/check.cpp | 12 ++++++++---- lib/check.h | 9 ++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/check.cpp b/lib/check.cpp index b13a3ea94e6..74de2d8689f 100644 --- a/lib/check.cpp +++ b/lib/check.cpp @@ -42,7 +42,11 @@ void Check::reportError(const ErrorLogger::ErrorMessage &errmsg) { std::cout << errmsg.toXML(true, 1) << std::endl; } -std::list &Check::instances() { - static std::list *_instances= new std::list; - return *_instances; - } + +#ifdef __SVR4 +std::list &Check::instances() +{ + static std::list *_instances= new std::list; + return *_instances; +} +#endif diff --git a/lib/check.h b/lib/check.h index acba45f346b..f928e269af8 100644 --- a/lib/check.h +++ b/lib/check.h @@ -53,7 +53,14 @@ class CPPCHECKLIB Check { } /** List of registered check classes. This is used by Cppcheck to run checks and generate documentation */ - static std::list &instances(); + #ifdef __SVR4 + static std::list &instances(); + #else + static std::list &instances() { + static std::list _instances; + return _instances; + } + #endif /** run checks, the token list is not simplified */ virtual void runChecks(const Tokenizer *, const Settings *, ErrorLogger *) {