diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index addf8b18c..b1147b9c8 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -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; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index a5a2e3794..ac30a35f0 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -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() {