Skip to content

Commit e1218cf

Browse files
committed
Support allocation of array of pointers with operator new in checkmemoryleak.cpp
1 parent 812bc6b commit e1218cf

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/checkmemoryleak.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
153153
Token::Match(tok2, "new ( nothrow ) struct| %type% [;()]"))
154154
return New;
155155

156-
if (Token::Match(tok2, "new struct| %type% [") ||
157-
Token::Match(tok2, "new ( std :: nothrow ) struct| %type% [") ||
158-
Token::Match(tok2, "new ( nothrow ) struct| %type% ["))
156+
if (Token::Match(tok2, "new struct| %type% *| [") ||
157+
Token::Match(tok2, "new ( std :: nothrow ) struct| %type% *| [") ||
158+
Token::Match(tok2, "new ( nothrow ) struct| %type% *| ["))
159159
return NewArray;
160160

161161
if (Token::Match(tok2, "fopen|tmpfile|g_fopen ("))

test/testmemleak.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ class TestMemleakInFunction : public TestFixture {
410410
ASSERT_EQUALS(";;alloc;", getcode("int *a = malloc(100);", "a"));
411411
ASSERT_EQUALS(";;alloc;", getcode("int *a = new int;", "a"));
412412
ASSERT_EQUALS(";;alloc;", getcode("int *a = new int[10];", "a"));
413+
ASSERT_EQUALS(";;alloc;", getcode("int **a = new int*[10];", "a"));
413414
ASSERT_EQUALS(";;alloc;", getcode("int * const a = new int[10];", "a"));
414415
ASSERT_EQUALS(";;alloc;", getcode("const int * const a = new int[10];", "a"));
415416
ASSERT_EQUALS(";;alloc;", getcode("int i = open(a,b);", "i"));

0 commit comments

Comments
 (0)