Skip to content

Commit

Permalink
Use leakIfAllocated()
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Nov 15, 2023
1 parent d1fcc3c commit 44d5541
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,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)) {
leakIfAllocated(arg, varInfo);
if (allocFunc->arg == argNr) {
VarInfo::AllocInfo& varAlloc = varInfo.alloctype[arg->varId()];
varAlloc.type = allocFunc->groupId;
Expand Down
7 changes: 7 additions & 0 deletions test/cfg/gnu.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,13 @@ void memleak_asprintf2() { // #12186
// cppcheck-suppress memleak
}

void memleak_asprintf3() {
char* p = malloc(5);
// cppcheck-suppress memleak
asprintf(&p, "%s", "test");
free(p);
}

void memleak_xmalloc()
{
char *p = (char*)xmalloc(10);
Expand Down

0 comments on commit 44d5541

Please sign in to comment.