Fix double free regression with smart pointers (#1184)
This commit is contained in:
parent
2073bd02d8
commit
bad66594d6
|
@ -562,7 +562,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
||||||
|
|
||||||
|
|
||||||
const Token * typeEndTok = ftok->linkAt(1);
|
const Token * typeEndTok = ftok->linkAt(1);
|
||||||
if (!Token::Match(typeEndTok, "> %var% {|( %var%"))
|
if (!Token::Match(typeEndTok, "> %var% {|( %var% ,|)|}"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool arrayDelete = false;
|
bool arrayDelete = false;
|
||||||
|
|
|
@ -73,6 +73,8 @@ private:
|
||||||
TEST_CASE(doublefree6); // #7685
|
TEST_CASE(doublefree6); // #7685
|
||||||
TEST_CASE(doublefree7);
|
TEST_CASE(doublefree7);
|
||||||
TEST_CASE(doublefree8);
|
TEST_CASE(doublefree8);
|
||||||
|
TEST_CASE(doublefree9);
|
||||||
|
|
||||||
|
|
||||||
// exit
|
// exit
|
||||||
TEST_CASE(exit1);
|
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());
|
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() {
|
void exit1() {
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" char *p = malloc(10);\n"
|
" char *p = malloc(10);\n"
|
||||||
|
|
Loading…
Reference in New Issue