Fix FP deallocuse regression (#5144)

Introduced in commit 69116c838 ("Fix #11758 Regression: memleak / Fix #11746 FN:
deallocuse (#5139)").
This commit is contained in:
Anton Lindqvist 2023-06-11 14:11:41 +02:00 committed by GitHub
parent f6a65afdee
commit 09cd3a8269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -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;

View File

@ -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"