Skip to content

Commit

Permalink
Fix #12996 FP memleak after checking for failure (#6671)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Aug 8, 2024
1 parent 4b40070 commit 9b79f3b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ void CheckLeakAutoVar::ret(const Token *tok, VarInfo &varInfo, const bool isEndO
const Token* const ifStart = ifEnd->link();
const Token* const alloc = it->second.allocTok;
if (precedes(ifStart, alloc) && succeeds(ifEnd, alloc)) { // allocation and check in if
if (Token::Match(outparamFunc->next()->astParent(), "%comp%"))
if (outparamFunc->next()->astParent() == ifStart || Token::Match(outparamFunc->next()->astParent(), "%comp%"))
continue;
} else { // allocation result assigned to variable
const Token* const retAssign = outparamFunc->next()->astParent();
Expand Down
9 changes: 9 additions & 0 deletions test/cfg/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,15 @@ void memleak_getaddrinfo_if() // #12506
}
}

void memleak_getaddrinfo_if2() // #12996
{
struct addrinfo *addrs = NULL;
if (getaddrinfo("a", "b", NULL, &addrs)) {
return;
}
freeaddrinfo(addrs);
}

void memleak_mmap(int fd)
{
// cppcheck-suppress [unusedAllocatedMemory, unreadVariable, constVariablePointer]
Expand Down

0 comments on commit 9b79f3b

Please sign in to comment.