Skip to content

Commit

Permalink
Fix #12890 FP mismatchAllocDealloc with pointer to pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Jul 13, 2024
1 parent 7aa5e4a commit 3401f22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
return No;
if (tok2->str() == "::")
tok2 = tok2->next();
while (Token::Match(tok2, "%name% :: %type%"))
tok2 = tok2->tokAt(2);
if (!tok2->isName())
return No;

if (!Token::Match(tok2, "%name% ::|. %type%")) {
if (!Token::Match(tok2, "%name% . %type%")) {
// Using realloc..
AllocType reallocType = getReallocationType(tok2, varid);
if (reallocType != No)
Expand Down Expand Up @@ -124,7 +126,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
}
}

while (Token::Match(tok2,"%name% ::|. %type%"))
while (Token::Match(tok2,"%name% . %type%"))
tok2 = tok2->tokAt(2);

// User function
Expand Down
13 changes: 13 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,19 @@ class TestLeakAutoVar : public TestFixture {
" delete[] li.front().m_p;\n"
"}\n", true);
ASSERT_EQUALS("", errout_str());

check("struct S {n" // #12890
" int** p;n"
" S() {n"
" p = std::malloc(sizeof(int*));n"
" p[0] = new int;n"
" }n"
" ~S() {n"
" delete p[0];n"
" std::free(p);n"
" }n"
"};\n", true);
ASSERT_EQUALS("", errout_str());
}

void assign26() {
Expand Down

0 comments on commit 3401f22

Please sign in to comment.