Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,9 @@ void CheckMemoryLeakStructMember::check()

const SymbolDatabase* symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Variable* var : symbolDatabase->variableList()) {
if (!var || (!var->isLocal() && !(var->isArgument() && var->scope())) || var->isStatic() || var->isReference())
if (!var || (!var->isLocal() && !(var->isArgument() && var->scope())) || var->isStatic())
continue;
if (var->isReference() || (var->valueType() && var->valueType()->pointer > 1))
continue;
if (var->typeEndToken()->isStandardType())
continue;
Expand All @@ -752,7 +754,7 @@ bool CheckMemoryLeakStructMember::isMalloc(const Variable *variable)
void CheckMemoryLeakStructMember::checkStructVariable(const Variable * const variable)
{
// Is struct variable a pointer?
if (variable->isPointer()) {
if (variable->isArrayOrPointer()) {
// Check that variable is allocated with malloc
if (!isMalloc(variable))
return;
Expand Down
16 changes: 16 additions & 0 deletions test/testmemleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,22 @@ class TestMemleakStructMember : public TestFixture {
" s->a[e] = strdup(n);\n"
"}\n", false);
ASSERT_EQUALS("", errout.str());

check("void f(struct S** s, const char* c) {\n"
" *s = malloc(sizeof(struct S));\n"
" (*s)->value = strdup(c);\n"
"}\n", false);
ASSERT_EQUALS("", errout.str());

check("struct S {\n"
" size_t mpsz;\n"
" void* hdr;\n"
"};\n"
"void f(struct S s[static 1U], int fd, size_t size) {\n"
" s->mpsz = size;\n"
" s->hdr = mmap(NULL, s->mpsz, PROT_READ, MAP_SHARED, fd, 0);\n"
"}\n", false);
ASSERT_EQUALS("", errout.str());
}

void failedAllocation() {
Expand Down