MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / isLocalVarNoAutoDealloc

Function isLocalVarNoAutoDealloc

lib/checkleakautovar.cpp:220–242  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218}
219
220static bool isLocalVarNoAutoDealloc(const Token *varTok)
221{
222 // not a local variable nor argument?
223 const Variable *var = varTok->variable();
224 if (!var)
225 return true;
226 if (!var->isArgument() && (!var->isLocal() || var->isStatic()))
227 return false;
228
229 // Don't check reference variables
230 if (var->isReference() && !var->isArgument())
231 return false;
232
233 // non-pod variable
234 if (varTok->isCpp()) {
235 // Possibly automatically deallocated memory
236 if (isAutoDealloc(var) && Token::Match(varTok, "%var% [=({] new"))
237 return false;
238 if (!var->isPointer() && !var->typeStartToken()->isStandardType())
239 return false;
240 }
241 return true;
242}
243
244/** checks if nameToken is a name of a function in a function call:
245 * func(arg)

Callers 1

checkScopeMethod · 0.85

Calls 3

isAutoDeallocFunction · 0.85
variableMethod · 0.80
isStandardTypeMethod · 0.45

Tested by

no test coverage detected