diff --git a/cfg/gtk.cfg b/cfg/gtk.cfg index 69842b096..4226b4666 100644 --- a/cfg/gtk.cfg +++ b/cfg/gtk.cfg @@ -18,7 +18,10 @@ g_register_data - g_strcmp + + + false + true diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 763f70610..73e891ebf 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -345,7 +345,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, if (dealloc == NOALLOC && Token::simpleMatch(tok, ") ; }")) { const std::string &functionName(tok->link()->previous()->str()); bool unknown = false; - if (_settings->library.ignore.find(functionName) == _settings->library.ignore.end() && + if (_settings->library.leakignore.find(functionName) == _settings->library.leakignore.end() && _settings->library.use.find(functionName) == _settings->library.use.end() && _tokenizer->IsScopeNoReturn(tok->tokAt(2), &unknown)) { if (unknown) { @@ -385,7 +385,7 @@ void CheckLeakAutoVar::functionCall(const Token *tok, VarInfo *varInfo, const in std::map &possibleUsage = varInfo->possibleUsage; // Ignore function call? - const bool ignore = bool(_settings->library.ignore.find(tok->str()) != _settings->library.ignore.end()); + const bool ignore = bool(_settings->library.leakignore.find(tok->str()) != _settings->library.leakignore.end()); if (ignore) return; diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index d422c573a..6499691ad 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -570,7 +570,7 @@ bool CheckMemoryLeakInFunction::test_white_list(const std::string &funcname) const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::list callstack, const unsigned int varid, AllocType &alloctype, AllocType &dealloctype, bool &allocpar, unsigned int sz) { if (test_white_list(tok->str()) || - (_settings->library.ignore.find(tok->str()) != _settings->library.ignore.end())) { + (_settings->library.leakignore.find(tok->str()) != _settings->library.leakignore.end())) { if (tok->str() == "asprintf" || tok->str() == "delete" || tok->str() == "fclose" || diff --git a/lib/library.cpp b/lib/library.cpp index 6ad6deddc..eef9f20e5 100644 --- a/lib/library.cpp +++ b/lib/library.cpp @@ -106,8 +106,6 @@ bool Library::load(const char exename[], const char path[]) } } - else if (strcmp(node->Name(),"ignore")==0) - ignore.insert(node->GetText()); else if (strcmp(node->Name(),"function")==0) { const char *name = node->Attribute("name"); if (name == NULL) @@ -116,6 +114,8 @@ bool Library::load(const char exename[], const char path[]) for (const tinyxml2::XMLElement *functionnode = node->FirstChildElement(); functionnode; functionnode = functionnode->NextSiblingElement()) { if (strcmp(functionnode->Name(),"noreturn")==0) _noreturn[name] = (strcmp(functionnode->GetText(), "true") == 0); + else if (strcmp(functionnode->Name(),"leak-ignore")==0) + leakignore.insert(name); else if (strcmp(functionnode->Name(),"arg")==0 && functionnode->Attribute("nr") != NULL) { const int nr = atoi(functionnode->Attribute("nr")); bool notnull = false; diff --git a/lib/library.h b/lib/library.h index 03556e253..043398edc 100644 --- a/lib/library.h +++ b/lib/library.h @@ -59,7 +59,7 @@ public: } std::set use; - std::set ignore; + std::set leakignore; bool isnoreturn(const std::string &name) const { std::map::const_iterator it = _noreturn.find(name); diff --git a/man/manual.docbook b/man/manual.docbook index 057d0bd5a..e020cc07b 100644 --- a/man/manual.docbook +++ b/man/manual.docbook @@ -753,7 +753,9 @@ Checking test.c... <dealloc>Unlock</dealloc> </resource> - <ignore>IsEqual</ignore> + <function name="IsEqual"> + <leak-ignore/> + </function> <function name="AssignFred"> <noreturn>false</noreturn> @@ -776,10 +778,10 @@ Checking test.c... CloseWilma. The <use> and - <ignore> elements are used to control the leaks - checking. If it should be ignored that a function is called, use - <ignore>. If there is no leak whenever the memory - is passed to a function, use <use>. + <leak-ignore> elements are used to control the + leaks checking. If it should be ignored that a function is called, use + <leak-ignore>. If there is no leak whenever the + memory is passed to a function, use <use>. In the <function> block some useful info is added about function behaviour. The <noreturn> @@ -797,12 +799,13 @@ Checking test.c... No configuration is necessary for the standard functions. The strcpy() was chosen in this example for demonstration purposes because - its behaviour is well-known. + its behaviour is well-known. The proper configuration for the standard strcpy() function would be: <function name="strcpy"> + <leak-ignore/> <noreturn>false</noreturn> <arg nr="1"> <not-null/> @@ -813,17 +816,22 @@ Checking test.c... </arg> </function> + The <leak-ignore/> is optional and it + tells Cppcheck to ignore this function call in the leaks checking. + Passing allocated memory to this function won't mean it will be + deallocated. + The <noreturn> is optional. But it's recommended. - The first parameter that the function takes is a pointer. It must + The first argument that the function takes is a pointer. It must not be a null pointer, a uninitialized pointer nor a dead pointer. It must point at some data, this data can be initialized but it is not wrong if it isn't. Using <not-null> is correct. Cppcheck will check by default that the pointer is not uninitialized nor dead. - The second parameter the function takes is a pointer. It must not + The second argument the function takes is a pointer. It must not be null. And it must point at initialized data. Using <not-null> and <not-uninit> is correct.