File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2501,7 +2501,7 @@ void CheckOther::checkDoubleFree()
25012501
25022502
25032503 // If a variable is passed to a function, remove it from the set of previously freed variables
2504- else if (Token::Match (tok, " %var% (" ) && !Token::Match (tok, " printf|sprintf|snprintf|fprintf|if|while " )) {
2504+ else if (Token::Match (tok, " %var% (" ) && !Token::Match (tok, " printf|sprintf|snprintf|fprintf" )) {
25052505
25062506 // If this is a new function definition, clear all variables
25072507 if (Token::simpleMatch (tok->next ()->link (), " ) {" )) {
@@ -2533,7 +2533,7 @@ void CheckOther::checkDoubleFree()
25332533
25342534 // Any control statements in-between delete, free() or closedir() statements
25352535 // makes it unclear whether any subsequent statements would be redundant.
2536- if (Token::Match (tok, " else|break|continue|goto|return|throw" )) {
2536+ if (Token::Match (tok, " if| else|for|while| break|continue|goto|return|throw|switch " )) {
25372537 freedVariables.clear ();
25382538 closeDirVariables.clear ();
25392539 }
Original file line number Diff line number Diff line change @@ -4614,6 +4614,22 @@ class TestOther : public TestFixture {
46144614 " }"
46154615 );
46164616 ASSERT_EQUALS (" " , errout.str ());
4617+
4618+ check (
4619+ " int foo()\n "
4620+ " {\n "
4621+ " int* a = new int;\n "
4622+ " bool doDelete = true;\n "
4623+ " if (a != 0)\n "
4624+ " {\n "
4625+ " doDelete = false;\n "
4626+ " delete a;\n "
4627+ " }\n "
4628+ " if(doDelete)\n "
4629+ " delete a;\n "
4630+ " return 0;\n "
4631+ " }"
4632+ );
46174633 }
46184634
46194635 void coutCerrMisusage () {
You can’t perform that action at this time.
0 commit comments