Fixed #5665: Recognize free() with more than one parameter

This commit is contained in:
PKEuS 2015-04-09 20:50:19 +02:00
parent d52b031301
commit 4e5c5eb238
2 changed files with 9 additions and 1 deletions

View File

@ -257,7 +257,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok
tok = tok->next();
if (Token::Match(tok, "free|kfree ( %varid% ) [;:]", varid) ||
Token::Match(tok, "free|kfree ( %varid% -", varid) ||
Token::Match(tok, "free|kfree ( %varid% -|,", varid) ||
Token::Match(tok, "realloc ( %varid% , 0 ) ;", varid))
return Malloc;

View File

@ -163,6 +163,7 @@ private:
TEST_CASE(simple7);
TEST_CASE(simple9); // Bug 2435468 - member function "free"
TEST_CASE(simple11);
TEST_CASE(nonstd_free);
TEST_CASE(new_nothrow);
TEST_CASE(staticvar);
@ -970,6 +971,13 @@ private:
ASSERT_EQUALS("", errout.str());
}
void nonstd_free() {
check("void f() {\n"
" void* mem = malloc(100, foo);" // Non-standard malloc() implementation
" free(mem, bar);" // Non-standard free() implementation (#5665)
"}");
ASSERT_EQUALS("", errout.str());
}
void new_nothrow() {