Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,18 +452,18 @@ void CheckLeakAutoVar::checkScope(const Token * const startToken,
while (tokRightAstOperand && tokRightAstOperand->isCast())
tokRightAstOperand = tokRightAstOperand->astOperand2() ? tokRightAstOperand->astOperand2() : tokRightAstOperand->astOperand1();
if (tokRightAstOperand && Token::Match(tokRightAstOperand->previous(), "%type% (")) {
const Library::AllocFunc* f = mSettings->library.getAllocFuncInfo(tokRightAstOperand->previous());
const Token * fTok = tokRightAstOperand->previous();
const Library::AllocFunc* f = mSettings->library.getAllocFuncInfo(fTok);
if (f && f->arg == -1) {
VarInfo::AllocInfo& varAlloc = alloctype[innerTok->varId()];
varAlloc.type = f->groupId;
varAlloc.status = VarInfo::ALLOC;
varAlloc.allocTok = tokRightAstOperand->previous();
varAlloc.allocTok = fTok;
} else {
// Fixme: warn about leak
alloctype.erase(innerTok->varId());
}

changeAllocStatusIfRealloc(alloctype, innerTok->tokAt(2), varTok);
changeAllocStatusIfRealloc(alloctype, fTok, varTok);
} else if (mTokenizer->isCPP() && Token::Match(innerTok->tokAt(2), "new !!(")) {
const Token* tok2 = innerTok->tokAt(2)->astOperand1();
const bool arrayNew = (tok2 && (tok2->str() == "[" || (tok2->str() == "(" && tok2->astOperand1() && tok2->astOperand1()->str() == "[")));
Expand Down
12 changes: 12 additions & 0 deletions test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ class TestLeakAutoVar : public TestFixture {
TEST_CASE(ifelse25); // #9966
TEST_CASE(ifelse26);
TEST_CASE(ifelse27);
TEST_CASE(ifelse28); // #11038

// switch
TEST_CASE(switch1);
Expand Down Expand Up @@ -1909,6 +1910,17 @@ class TestLeakAutoVar : public TestFixture {
ASSERT_EQUALS("", errout.str());
}

void ifelse28() { // #11038
check("char * f(void) {\n"
" char *buf = (char*)malloc(42*sizeof(char));\n"
" char *temp;\n"
" if ((temp = (char*)realloc(buf, 16)) != NULL)\n"
" { buf = temp; }\n"
" return buf;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void switch1() {
check("void f() {\n"
" char *p = 0;\n"
Expand Down