Fixed #3987 (False positive: Memory leak reported when throwing/catching)
This commit is contained in:
parent
6d928a2ff7
commit
d3e990b1e5
|
@ -462,10 +462,16 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
|
|||
}
|
||||
|
||||
// return
|
||||
else if (tok->str() == "return" || tok->str() == "throw") {
|
||||
else if (tok->str() == "return") {
|
||||
ret(tok, *varInfo);
|
||||
varInfo->clear();
|
||||
}
|
||||
|
||||
// throw
|
||||
// TODO: if the execution leave the function then treat it as return
|
||||
else if (tok->str() == "throw") {
|
||||
varInfo->clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -90,6 +90,9 @@ private:
|
|||
TEST_CASE(test2);
|
||||
TEST_CASE(test3); // #3954 - reference pointer
|
||||
|
||||
// Execution reaches a 'throw'
|
||||
TEST_CASE(throw1);
|
||||
|
||||
// Possible leak => Further configuration is needed for complete analysis
|
||||
TEST_CASE(configuration1);
|
||||
TEST_CASE(configuration2);
|
||||
|
@ -509,6 +512,24 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void throw1() { // 3987 - Execution reach a 'throw'
|
||||
check("void f() {\n"
|
||||
" char *p = malloc(10);\n"
|
||||
" throw 123;\n"
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("error", "", errout.str());
|
||||
|
||||
check("void f() {\n"
|
||||
" char *p;\n"
|
||||
" try {\n"
|
||||
" p = malloc(10);\n"
|
||||
" throw 123;\n"
|
||||
" } catch (...) { }\n"
|
||||
" free(p);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void configuration1() {
|
||||
// Possible leak => configuration is required for complete analysis
|
||||
// The user should be able to "white list" and "black list" functions.
|
||||
|
|
Loading…
Reference in New Issue