Skip to content

Commit f434314

Browse files
simartinPKEuS
authored andcommitted
Ticket #7685: Properly handle function calls as argument to a dealloc function. (#853)
Add an optional extended description…
1 parent 21ab39e commit f434314

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

lib/checkleakautovar.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,11 @@ void CheckLeakAutoVar::functionCall(const Token *tok, VarInfo *varInfo, const Va
546546
if (!af || af->arg == argNr)
547547
changeAllocStatus(varInfo, allocation, tok, arg);
548548
} else if (Token::Match(arg, "%name% (")) {
549-
functionCall(arg, varInfo, allocation, af);
549+
const Library::AllocFunc* allocFunc = _settings->library.dealloc(arg);
550+
VarInfo::AllocInfo alloc(allocFunc ? allocFunc->groupId : 0, VarInfo::DEALLOC);
551+
if (alloc.type == 0)
552+
alloc.status = VarInfo::NOALLOC;
553+
functionCall(arg, varInfo, alloc, allocFunc);
550554
}
551555
argNr++;
552556
}

test/testleakautovar.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class TestLeakAutoVar : public TestFixture {
6666
TEST_CASE(doublefree3); // #4914
6767
TEST_CASE(doublefree4); // #5451 - FP when exit is called
6868
TEST_CASE(doublefree5); // #5522
69+
TEST_CASE(doublefree6); // #7685
6970

7071
// exit
7172
TEST_CASE(exit1);
@@ -822,6 +823,14 @@ class TestLeakAutoVar : public TestFixture {
822823
ASSERT_EQUALS("[test.c:4]: (error) Memory pointed to by 'p' is freed twice.\n", errout.str());
823824
}
824825

826+
void doublefree6() { // #7685
827+
check("void do_wordexp(FILE *f) {\n"
828+
" free(getword(f));\n"
829+
" fclose(f);\n"
830+
"}", /*cpp=*/false);
831+
ASSERT_EQUALS("", errout.str());
832+
}
833+
825834
void exit1() {
826835
check("void f() {\n"
827836
" char *p = malloc(10);\n"

0 commit comments

Comments
 (0)