From 423e67bd6ac7635c3fe03a49c803223d21d19427 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Mon, 30 May 2022 06:55:15 +0200 Subject: [PATCH] Fix FP memleak (#4145) --- lib/checkmemoryleak.cpp | 10 +++++++--- test/testmemleak.cpp | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 85bd8d21e..9169b09e2 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -835,9 +835,13 @@ void CheckMemoryLeakStructMember::checkStructVariable(const Variable * const var if (getAllocationType(assignToks.second, assignToks.first->varId()) == AllocType::No) continue; - if (variable->isArgument() && variable->valueType() && variable->valueType()->type == ValueType::UNKNOWN_TYPE && - Token::simpleMatch(assignToks.first->astParent(), ".") && assignToks.first->astParent()->originalName() == "->") - continue; + if (variable->isArgument() && variable->valueType() && variable->valueType()->type == ValueType::UNKNOWN_TYPE && assignToks.first->astParent()) { + const Token* accessTok = assignToks.first->astParent(); + while (Token::simpleMatch(accessTok->astOperand1(), ".")) + accessTok = accessTok->astOperand1(); + if (Token::simpleMatch(accessTok, ".") && accessTok->originalName() == "->") + continue; + } const int structid(variable->declarationId()); const int structmemberid(assignToks.first->varId()); diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index c0c35b672..fc19c4081 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -1949,6 +1949,8 @@ private: check("void f(type_t t) {\n" " t->p = malloc(10);\n" + " t->x.p = malloc(10);\n" + " t->y[2].p = malloc(10);\n" "}\n", false); ASSERT_EQUALS("", errout.str()); }