Fix CI; Cppcheck find some more unusedAllocatedMemory violations in test/cfg/..

This commit is contained in:
Daniel Marjamäki 2021-05-13 23:08:58 +02:00
parent fd31f0846e
commit 45eb9f82a0
5 changed files with 11 additions and 3 deletions

View File

@ -940,9 +940,11 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
else if (var && var->mType == Variables::pointer && else if (var && var->mType == Variables::pointer &&
Token::Match(start, "%name% =") && Token::Match(start, "%name% =") &&
findAllocFuncCallToken(start->next()->astOperand2(), mSettings->library)) { findAllocFuncCallToken(start->next()->astOperand2(), mSettings->library)) {
bool allocate = true;
const Token *allocFuncCallToken = findAllocFuncCallToken(start->next()->astOperand2(), mSettings->library); const Token *allocFuncCallToken = findAllocFuncCallToken(start->next()->astOperand2(), mSettings->library);
const Library::AllocFunc *allocFunc = mSettings->library.getAllocFuncInfo(allocFuncCallToken);
bool allocateMemory = !allocFunc || Library::ismemory(allocFunc->groupId);
if (allocFuncCallToken->str() == "new") { if (allocFuncCallToken->str() == "new") {
const Token *type = allocFuncCallToken->next(); const Token *type = allocFuncCallToken->next();
@ -956,11 +958,11 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
if (!type->isStandardType()) { if (!type->isStandardType()) {
const Variable *variable = start->variable(); const Variable *variable = start->variable();
if (!variable || !isRecordTypeWithoutSideEffects(variable->type())) if (!variable || !isRecordTypeWithoutSideEffects(variable->type()))
allocate = false; allocateMemory = false;
} }
} }
if (allocate) if (allocateMemory)
variables.allocateMemory(varid1, tok); variables.allocateMemory(varid1, tok);
else else
variables.write(varid1, tok); variables.write(varid1, tok);

View File

@ -197,6 +197,7 @@ void memleak_getaddrinfo()
void memleak_mmap(int fd) void memleak_mmap(int fd)
{ {
// cppcheck-suppress unusedAllocatedMemory
// cppcheck-suppress unreadVariable // cppcheck-suppress unreadVariable
void *addr = mmap(NULL, 255, PROT_NONE, MAP_PRIVATE, fd, 0); void *addr = mmap(NULL, 255, PROT_NONE, MAP_PRIVATE, fd, 0);
// cppcheck-suppress memleak // cppcheck-suppress memleak

View File

@ -48,6 +48,7 @@ void PyMem_Malloc_memleak()
void PyMem_Malloc_mismatchAllocDealloc() void PyMem_Malloc_mismatchAllocDealloc()
{ {
// cppcheck-suppress unusedAllocatedMemory
char * pBuf1 = PyMem_Malloc(10); char * pBuf1 = PyMem_Malloc(10);
// cppcheck-suppress mismatchAllocDealloc // cppcheck-suppress mismatchAllocDealloc
free(pBuf1); free(pBuf1);

View File

@ -87,6 +87,7 @@ void bufferAccessOutOfBounds(void)
void memleak_aligned_alloc(void) void memleak_aligned_alloc(void)
{ {
// cppcheck-suppress unusedAllocatedMemory
// cppcheck-suppress unreadVariable // cppcheck-suppress unreadVariable
char * alignedBuf = aligned_alloc(8, 16); char * alignedBuf = aligned_alloc(8, 16);
// cppcheck-suppress memleak // cppcheck-suppress memleak
@ -1118,6 +1119,7 @@ void uninitvar_calloc(void)
{ {
size_t nitems; size_t nitems;
size_t size; size_t size;
// cppcheck-suppress unusedAllocatedMemory
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
int * p = (int*) calloc(nitems, size); int * p = (int*) calloc(nitems, size);
free(p); free(p);
@ -2598,6 +2600,7 @@ void uninitvar_longjmp(void)
void uninitvar_malloc(void) void uninitvar_malloc(void)
{ {
size_t size; size_t size;
// cppcheck-suppress unusedAllocatedMemory
// cppcheck-suppress uninitvar // cppcheck-suppress uninitvar
int *p = (int*)malloc(size); int *p = (int*)malloc(size);
free(p); free(p);

View File

@ -403,6 +403,7 @@ void nullPointer()
void memleak_malloca() void memleak_malloca()
{ {
// cppcheck-suppress unusedAllocatedMemory
// cppcheck-suppress unreadVariable // cppcheck-suppress unreadVariable
void *pMem = _malloca(10); void *pMem = _malloca(10);
// cppcheck-suppress memleak // cppcheck-suppress memleak