From 09cd3a82698abd11b071f4d8f496a574c8ddca12 Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Sun, 11 Jun 2023 14:11:41 +0200 Subject: [PATCH] Fix FP deallocuse regression (#5144) Introduced in commit 69116c838 ("Fix #11758 Regression: memleak / Fix #11746 FN: deallocuse (#5139)"). --- lib/checkleakautovar.cpp | 2 +- test/testleakautovar.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index fd6246b4d..ea5eae921 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -1068,7 +1068,7 @@ void CheckLeakAutoVar::ret(const Token *tok, VarInfo &varInfo, const bool isEndO tok2 = tok3->next(); else if (Token::Match(tok3, "& %varid% . %name%", varid)) tok2 = tok3->tokAt(4); - else if (Token::simpleMatch(tok3, "*")) + else if (Token::simpleMatch(tok3, "*") && tok3->next()->varId() == varid) tok2 = tok3; else continue; diff --git a/test/testleakautovar.cpp b/test/testleakautovar.cpp index e5f5005e5..82da49a40 100644 --- a/test/testleakautovar.cpp +++ b/test/testleakautovar.cpp @@ -113,6 +113,7 @@ private: TEST_CASE(deallocuse9); // #9781 TEST_CASE(deallocuse10); TEST_CASE(deallocuse11); // #8302 + TEST_CASE(deallocuse12); TEST_CASE(doublefree1); TEST_CASE(doublefree2); @@ -858,6 +859,17 @@ private: ASSERT_EQUALS("[test.c:3] -> [test.c:4]: (error) Returning/dereferencing 'array' after it is deallocated / released\n", errout.str()); } + void deallocuse12() { + check("struct foo { int x; }\n" + "void f1(struct foo *f) {\n" + " free(f);\n" + "}\n" + "void f2(struct foo *f, int *out) {\n" + " *out = f->x;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void doublefree1() { // #3895 check("void f(char *p) {\n" " if (x)\n"