From 4e5c5eb238cb9c593c56e0593fa196723846a19f Mon Sep 17 00:00:00 2001 From: PKEuS Date: Thu, 9 Apr 2015 20:50:19 +0200 Subject: [PATCH] Fixed #5665: Recognize free() with more than one parameter --- lib/checkmemoryleak.cpp | 2 +- test/testmemleak.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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() {