Fixed #3862 (Double deallocation does not take throws into account)

This commit is contained in:
Daniel Marjamäki 2012-06-01 19:08:50 +02:00
parent a823d29da3
commit 0cf2c2b327
2 changed files with 13 additions and 1 deletions

View File

@ -393,7 +393,7 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
}
// return
else if (tok->str() == "return") {
else if (tok->str() == "return" || tok->str() == "throw") {
ret(tok, *varInfo);
varInfo->clear();
}

View File

@ -77,6 +77,7 @@ private:
TEST_CASE(return1);
TEST_CASE(return2);
TEST_CASE(return3);
TEST_CASE(return4);
// General tests: variable type, allocation type, etc
TEST_CASE(test1);
@ -381,6 +382,17 @@ private:
ASSERT_EQUALS("", errout.str());
}
void return4() {
check("void f(char *p, int x) {\n"
" if (x==12) {n"
" free(p);\n"
" throw 1;\n"
" }\n"
" free(p);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void test1() { // 3809
check("void f(double*&p) {\n"
" p = malloc(0x100);\n"