Skip to content

Commit 8e62a24

Browse files
Fix #13918 FP doubleFree reported for struct member freed in ifs (danmar#7619)
1 parent 539aa4f commit 8e62a24

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/checkleakautovar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ void CheckLeakAutoVar::functionCall(const Token *tokName, const Token *tokOpenin
10241024
arg = arg->astOperand2() ? arg->astOperand2() : arg->astOperand1();
10251025
const Token * const argTypeStartTok = arg;
10261026

1027-
while (Token::Match(arg, "%name% .|:: %name%"))
1027+
while (Token::Match(arg, "%name% :: %name%"))
10281028
arg = arg->tokAt(2);
10291029

10301030
if ((Token::Match(arg, "%var% [-,)] !!.") && !(arg->variable() && arg->variable()->isArray())) ||

test/testleakautovar.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class TestLeakAutoVar : public TestFixture {
108108
TEST_CASE(doublefree15);
109109
TEST_CASE(doublefree16);
110110
TEST_CASE(doublefree17); // #8109: delete with comma operator
111+
TEST_CASE(doublefree18);
111112

112113
// exit
113114
TEST_CASE(exit1);
@@ -1801,6 +1802,18 @@ class TestLeakAutoVar : public TestFixture {
18011802
ASSERT_EQUALS("[test.cpp:5:5] -> [test.cpp:6:16]: (error) Memory pointed to by 'c' is freed twice. [doubleFree]\n", errout_str());
18021803
}
18031804

1805+
void doublefree18() {
1806+
check("typedef struct {\n" // #13918
1807+
" FILE * fp;\n"
1808+
"} S;\n"
1809+
"void f(S* s, FILE* x) {\n"
1810+
" if (fclose(s->fp)) {}\n"
1811+
" s->fp = x;\n"
1812+
" if (fclose(s->fp)) {}\n"
1813+
"}\n");
1814+
ASSERT_EQUALS("", errout_str());
1815+
}
1816+
18041817
void exit1() {
18051818
check("void f() {\n"
18061819
" char *p = malloc(10);\n"

0 commit comments

Comments
 (0)