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