diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 9e57c95ae84..3894de25521 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -971,7 +971,7 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin const Library::AllocFunc* deallocFunc = mSettings->library.getDeallocFuncInfo(tokName); VarInfo::AllocInfo dealloc(deallocFunc ? deallocFunc->groupId : 0, VarInfo::DEALLOC, tokName); if (const Library::AllocFunc* allocFunc = mSettings->library.getAllocFuncInfo(tokName)) { - if (allocFunc->arg == argNr) { + if (allocFunc->arg == argNr && !(arg->variable() && arg->variable()->isArgument() && arg->valueType() && arg->valueType()->pointer > 1)) { leakIfAllocated(arg, varInfo); VarInfo::AllocInfo& varAlloc = varInfo.alloctype[arg->varId()]; varAlloc.type = allocFunc->groupId; diff --git a/test/cfg/gnu.c b/test/cfg/gnu.c index d2ded37e540..d7fbe6d6667 100644 --- a/test/cfg/gnu.c +++ b/test/cfg/gnu.c @@ -355,7 +355,6 @@ void memleak_asprintf(char **ptr, const char *fmt, const int arg) free(ptr); } if (-1 != asprintf(ptr,fmt,arg)) {} - // cppcheck-suppress memleak } void memleak_asprintf2() { // #12186 @@ -372,6 +371,15 @@ void memleak_asprintf3() { free(p); } +void memleak_asprintf4(char** p) { + asprintf(p, "%s", "test"); +} + +void memleak_asprintf5(char* p) { + asprintf(&p, "%s", "test"); + // cppcheck-suppress memleak +} + void memleak_xmalloc() { char *p = (char*)xmalloc(10);