diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index f9465163097..5007d923b33 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -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(); diff --git a/test/cfg/posix.c b/test/cfg/posix.c index f135ea7d6de..69da6db2b2b 100644 --- a/test/cfg/posix.c +++ b/test/cfg/posix.c @@ -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]