Fix #8282 (memleak FP when returning std::pair) (#2039)

This commit is contained in:
Rikard Falkeborn 2019-07-26 07:03:58 +02:00 committed by Daniel Marjamäki
parent ee28a45db4
commit f95d193e22
2 changed files with 11 additions and 2 deletions

View File

@ -932,11 +932,11 @@ void CheckLeakAutoVar::ret(const Token *tok, const VarInfo &varInfo)
for (const Token *tok2 = tok; tok2; tok2 = tok2->next()) { for (const Token *tok2 = tok; tok2; tok2 = tok2->next()) {
if (tok2->str() == ";") if (tok2->str() == ";")
break; break;
if (Token::Match(tok2, "return|(|, %varid% [);,]", varid)) { if (Token::Match(tok2, "return|(|{|, %varid% [});,]", varid)) {
used = true; used = true;
break; break;
} }
if (Token::Match(tok2, "return|(|, & %varid% . %name% [);,]", varid)) { if (Token::Match(tok2, "return|(|{|, & %varid% . %name% [});,]", varid)) {
used = true; used = true;
break; break;
} }

View File

@ -142,6 +142,7 @@ private:
TEST_CASE(return3); TEST_CASE(return3);
TEST_CASE(return4); TEST_CASE(return4);
TEST_CASE(return5); TEST_CASE(return5);
TEST_CASE(return6); // #8282 return {p, p}
// General tests: variable type, allocation type, etc // General tests: variable type, allocation type, etc
TEST_CASE(test1); TEST_CASE(test1);
@ -1658,6 +1659,14 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void return6() { // #8282
check("std::pair<char*, char*> f(size_t n) {\n"
" char* p = (char* )malloc(n);\n"
" return {p, p};\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"