diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 355d37939..5cdd3ecb6 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -123,6 +123,8 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2, return Malloc; if (tokenizer->isCPP() && tok2->str() == "new") { + if (tok2->strAt(1) == "(" && !Token::Match(tok2->next(),"( std| ::| nothrow )")) + return No; if (tok2->astOperand1() && (tok2->astOperand1()->str() == "[" || (tok2->astOperand1()->astOperand1() && tok2->astOperand1()->astOperand1()->str() == "["))) return NewArray; return New; diff --git a/test/testmemleak.cpp b/test/testmemleak.cpp index 3bffc1154..8e0beebb5 100644 --- a/test/testmemleak.cpp +++ b/test/testmemleak.cpp @@ -410,6 +410,7 @@ private: ASSERT_EQUALS(";;alloc;", getcode("int **a = new int*[10];", "a")); ASSERT_EQUALS(";;alloc;", getcode("int * const a = new int[10];", "a")); ASSERT_EQUALS(";;alloc;", getcode("const int * const a = new int[10];", "a")); + ASSERT_EQUALS(";;assign;", getcode("A * a = new (X) A;", "a")); ASSERT_EQUALS(";;alloc;", getcode("int i = open(a,b);", "i")); ASSERT_EQUALS(";;assign;", getcode("int i = open();", "i"));