diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 0a9d1406e..c1012de11 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -232,7 +232,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, // allocation? if (Token::Match(tok->tokAt(2), "%type% (")) { - int i = _settings->library.alloc(tok->strAt(2)); + int i = _settings->library.alloc(tok->tokAt(2)); if (i > 0) { alloctype[tok->varId()] = i; } @@ -255,7 +255,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, if (innerTok->str() == ")") break; if (innerTok->str() == "(" && innerTok->previous()->isName()) { - const int deallocId = _settings->library.dealloc(tok->str()); + const int deallocId = _settings->library.dealloc(tok); functionCall(innerTok->previous(), varInfo, deallocId); innerTok = innerTok->link(); } @@ -343,7 +343,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken, // Function call.. else if (Token::Match(tok, "%type% (") && tok->str() != "return") { - const int dealloc = _settings->library.dealloc(tok->str()); + const int dealloc = _settings->library.dealloc(tok); functionCall(tok, varInfo, dealloc); diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 168a43209..1c4dd2187 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -180,7 +180,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2, } // Does tok2 point on "g_malloc", "g_strdup", .. - const int alloctype = settings1->library.alloc(tok2->str()); + const int alloctype = settings1->library.alloc(tok2); if (alloctype > 0) { if (alloctype == settings1->library.dealloc("free")) return Malloc; @@ -271,7 +271,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok // Does tok2 point on "g_free", etc .. if (Token::Match(tok, "%type% ( %varid% )", varid)) { - const int dealloctype = settings1->library.dealloc(tok->str()); + const int dealloctype = settings1->library.dealloc(tok); if (dealloctype > 0) return Library::ismemory(dealloctype) ? OtherMem : OtherRes; } @@ -309,7 +309,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok return Pipe; if (Token::Match(tok, ("%type% ( " + varname + " )").c_str())) { - int type = settings1->library.dealloc(tok->str()); + int type = settings1->library.dealloc(tok); if (type > 0) return Library::ismemory(type) ? OtherMem : OtherRes; } @@ -2764,7 +2764,7 @@ void CheckMemoryLeakNoVar::checkForUnusedReturnValue(const Scope *scope) for (const Token *tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { if (Token::Match(tok, "{|}|; %var% (")) { tok = tok->next(); - const int allocationId = _settings->library.alloc(tok->str()); + const int allocationId = _settings->library.alloc(tok); if (allocationId > 0) returnValueNotUsedError(tok, tok->str()); } diff --git a/lib/library.h b/lib/library.h index 16f09eb8b..d3b20c91b 100644 --- a/lib/library.h +++ b/lib/library.h @@ -24,6 +24,7 @@ #include "config.h" #include "path.h" #include "mathlib.h" +#include "token.h" #include #include @@ -50,13 +51,23 @@ public: bool loadxmldata(const char xmldata[], std::size_t len); bool load(const tinyxml2::XMLDocument &doc); - /** get allocation id for function (by name) */ - int alloc(const std::string &name) const { + /** get allocation id for function by name */ + int alloc(const char name[]) const { return getid(_alloc, name); } - /** get deallocation id for function (by name) */ - int dealloc(const std::string &name) const { + /** get allocation id for function */ + int alloc(const Token *tok) const { + return tok->function() ? 0 : getid(_alloc, tok->str()); + } + + /** get deallocation id for function */ + int dealloc(const Token *tok) const { + return tok->function() ? 0 : getid(_dealloc, tok->str()); + } + + /** get deallocation id for function by name */ + int dealloc(const char name[]) const { return getid(_dealloc, name); }