Fix double free regression with smart pointers (#1184)

This commit is contained in:
Paul Fultz II 2018-04-21 04:24:19 -05:00 committed by Daniel Marjamäki
parent 2073bd02d8
commit bad66594d6
2 changed files with 14 additions and 1 deletions

View File

@ -562,7 +562,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
const Token * typeEndTok = ftok->linkAt(1);
if (!Token::Match(typeEndTok, "> %var% {|( %var%"))
if (!Token::Match(typeEndTok, "> %var% {|( %var% ,|)|}"))
continue;
bool arrayDelete = false;

View File

@ -73,6 +73,8 @@ private:
TEST_CASE(doublefree6); // #7685
TEST_CASE(doublefree7);
TEST_CASE(doublefree8);
TEST_CASE(doublefree9);
// exit
TEST_CASE(exit1);
@ -944,6 +946,17 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (error) Memory pointed to by 'i' is freed twice.\n", errout.str());
}
void doublefree9() {
check("struct foo {\n"
" int* get(int) { return new int(); }\n"
"};\n"
"void f(foo* b) {\n"
" std::unique_ptr<int> x(b->get(0));\n"
" std::unique_ptr<int> y(b->get(1));\n"
"}\n", true);
ASSERT_EQUALS("", errout.str());
}
void exit1() {
check("void f() {\n"
" char *p = malloc(10);\n"