Skip to content

Commit 9b79f3b

Browse files
Fix #12996 FP memleak after checking for failure (#6671)
1 parent 4b40070 commit 9b79f3b

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/checkleakautovar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ void CheckLeakAutoVar::ret(const Token *tok, VarInfo &varInfo, const bool isEndO
11531153
const Token* const ifStart = ifEnd->link();
11541154
const Token* const alloc = it->second.allocTok;
11551155
if (precedes(ifStart, alloc) && succeeds(ifEnd, alloc)) { // allocation and check in if
1156-
if (Token::Match(outparamFunc->next()->astParent(), "%comp%"))
1156+
if (outparamFunc->next()->astParent() == ifStart || Token::Match(outparamFunc->next()->astParent(), "%comp%"))
11571157
continue;
11581158
} else { // allocation result assigned to variable
11591159
const Token* const retAssign = outparamFunc->next()->astParent();

test/cfg/posix.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,15 @@ void memleak_getaddrinfo_if() // #12506
10571057
}
10581058
}
10591059

1060+
void memleak_getaddrinfo_if2() // #12996
1061+
{
1062+
struct addrinfo *addrs = NULL;
1063+
if (getaddrinfo("a", "b", NULL, &addrs)) {
1064+
return;
1065+
}
1066+
freeaddrinfo(addrs);
1067+
}
1068+
10601069
void memleak_mmap(int fd)
10611070
{
10621071
// cppcheck-suppress [unusedAllocatedMemory, unreadVariable, constVariablePointer]

0 commit comments

Comments
 (0)