Fix false positive in memory leak

This commit is contained in:
Binho 2022-03-10 08:29:05 +01:00 committed by Daniel Marjamäki
parent 7290ec0db6
commit 8b3647edd7
2 changed files with 10 additions and 1 deletions

View File

@ -1006,7 +1006,7 @@ void CheckLeakAutoVar::ret(const Token *tok, VarInfo &varInfo, const bool isEndO
tok2 = tok3->tokAt(4); tok2 = tok3->tokAt(4);
else else
continue; continue;
if (Token::Match(tok2, "[});,]")) { if (Token::Match(tok2, "[});,+]")) {
used = true; used = true;
break; break;
} }

View File

@ -184,6 +184,7 @@ private:
TEST_CASE(return6); // #8282 return {p, p} TEST_CASE(return6); // #8282 return {p, p}
TEST_CASE(return7); // #9343 return (uint8_t*)x TEST_CASE(return7); // #9343 return (uint8_t*)x
TEST_CASE(return8); TEST_CASE(return8);
TEST_CASE(return9);
// General tests: variable type, allocation type, etc // General tests: variable type, allocation type, etc
TEST_CASE(test1); TEST_CASE(test1);
@ -2104,6 +2105,14 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void return9() {
check("void* f() {\n"
" void *x = malloc (sizeof (struct alloc));\n"
" return x + sizeof (struct alloc);\n"
"}", true);
ASSERT_EQUALS("", errout.str());
}
void test1() { // 3809 void test1() { // 3809
check("void f(double*&p) {\n" check("void f(double*&p) {\n"
" p = malloc(0x100);\n" " p = malloc(0x100);\n"