Fix FP memleak (f'up to #12186) (#5671)

This commit is contained in:
chrchr-github 2023-11-16 18:35:32 +01:00 committed by GitHub
parent 4b9f3c68fb
commit 3e47acd580
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -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;

View File

@ -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);