parent
9cf0342f9d
commit
63a5a71c20
|
@ -970,10 +970,17 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin
|
|||
if (!isnull && (!af || af->arg == argNr)) {
|
||||
const Library::AllocFunc* deallocFunc = mSettings->library.getDeallocFuncInfo(tokName);
|
||||
VarInfo::AllocInfo dealloc(deallocFunc ? deallocFunc->groupId : 0, VarInfo::DEALLOC, tokName);
|
||||
if (dealloc.type == 0)
|
||||
changeAllocStatus(varInfo, allocation, tokName, arg);
|
||||
if (const Library::AllocFunc* allocFunc = mSettings->library.getAllocFuncInfo(tokName)) {
|
||||
if (allocFunc->arg == argNr) {
|
||||
leakIfAllocated(arg, varInfo);
|
||||
VarInfo::AllocInfo& varAlloc = varInfo.alloctype[arg->varId()];
|
||||
varAlloc.type = allocFunc->groupId;
|
||||
varAlloc.status = VarInfo::ALLOC;
|
||||
varAlloc.allocTok = arg;
|
||||
}
|
||||
}
|
||||
else
|
||||
changeAllocStatus(varInfo, dealloc, tokName, arg);
|
||||
changeAllocStatus(varInfo, dealloc.type == 0 ? allocation : dealloc, tokName, arg);
|
||||
}
|
||||
}
|
||||
// Check smart pointer
|
||||
|
|
|
@ -354,9 +354,22 @@ void memleak_asprintf(char **ptr, const char *fmt, const int arg)
|
|||
if (-1 != asprintf(ptr,fmt,arg)) {
|
||||
free(ptr);
|
||||
}
|
||||
if (-1 != asprintf(ptr,fmt,arg)) {
|
||||
// TODO: Related to #8980 cppcheck-suppress memleak
|
||||
}
|
||||
if (-1 != asprintf(ptr,fmt,arg)) {}
|
||||
// cppcheck-suppress memleak
|
||||
}
|
||||
|
||||
void memleak_asprintf2() { // #12186
|
||||
char* p = malloc(5);
|
||||
// cppcheck-suppress memleak
|
||||
(void)asprintf(&p, "%s", "test");
|
||||
// cppcheck-suppress memleak
|
||||
}
|
||||
|
||||
void memleak_asprintf3() {
|
||||
char* p = malloc(5);
|
||||
// cppcheck-suppress memleak
|
||||
asprintf(&p, "%s", "test");
|
||||
free(p);
|
||||
}
|
||||
|
||||
void memleak_xmalloc()
|
||||
|
|
|
@ -43,7 +43,7 @@ void resourceLeak_sqlite3_open()
|
|||
sqlite3 * db;
|
||||
|
||||
sqlite3_open("/db", &db);
|
||||
// TODO: cppcheck-suppress resourceLeak
|
||||
// cppcheck-suppress resourceLeak
|
||||
}
|
||||
|
||||
void ignoredReturnValue(const char * buf)
|
||||
|
|
|
@ -3014,8 +3014,7 @@ private:
|
|||
" HeapFree(MyHeap, 0, a);"
|
||||
" HeapFree(MyHeap, 0, b);"
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("[test.c:1] (error) Resource leak: MyHeap",
|
||||
"", errout.str());
|
||||
ASSERT_EQUALS("[test.c:1]: (error) Resource leak: MyHeap\n", errout.str());
|
||||
|
||||
check("void f() {"
|
||||
" HANDLE MyHeap = HeapCreate(0, 0, 0);"
|
||||
|
@ -3023,9 +3022,9 @@ private:
|
|||
" int *b = HeapAlloc(MyHeap, 0, sizeof(int));"
|
||||
" HeapFree(MyHeap, 0, a);"
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("[test.c:1] (error) Memory leak: MyHeap\n"
|
||||
"[test.c:1] (error) Memory leak: b",
|
||||
"[test.c:1]: (error) Memory leak: b\n", errout.str());
|
||||
ASSERT_EQUALS("[test.c:1]: (error) Resource leak: MyHeap\n"
|
||||
"[test.c:1]: (error) Memory leak: b\n",
|
||||
errout.str());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue