Skip to content

Commit

Permalink
Fix FP memleak (f'up to #12186) (#5671)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github authored Nov 16, 2023
1 parent 4b9f3c6 commit 3e47acd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion test/cfg/gnu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 3e47acd

Please sign in to comment.