| 978 | |
| 979 | |
| 980 | void CheckLeakAutoVarImpl::changeAllocStatus(VarInfo &varInfo, const VarInfo::AllocInfo& allocation, const Token* tok, const Token* arg) |
| 981 | { |
| 982 | std::map<int, VarInfo::AllocInfo> &alloctype = varInfo.alloctype; |
| 983 | const auto var = alloctype.find(arg->varId()); |
| 984 | if (var != alloctype.end()) { |
| 985 | // bailout if function is also allocating, since the argument might be moved |
| 986 | // to the return value, such as in fdopen |
| 987 | if (allocation.allocTok && mSettings.library.getAllocFuncInfo(allocation.allocTok)) { |
| 988 | varInfo.erase(arg->varId()); |
| 989 | return; |
| 990 | } |
| 991 | if (allocation.status == VarInfo::NOALLOC) { |
| 992 | // possible usage |
| 993 | varInfo.possibleUsage[arg->varId()] = { tok, VarInfo::USED }; |
| 994 | if (var->second.status == VarInfo::DEALLOC && arg->strAt(-1) == "&") |
| 995 | varInfo.erase(arg->varId()); |
| 996 | } else if (var->second.managed()) { |
| 997 | doubleFreeError(tok, var->second.allocTok, arg->str(), allocation.type); |
| 998 | var->second.status = allocation.status; |
| 999 | } else if (var->second.type != allocation.type && var->second.type != 0) { |
| 1000 | // mismatching allocation and deallocation |
| 1001 | mismatchError(tok, var->second.allocTok, arg->str()); |
| 1002 | varInfo.erase(arg->varId()); |
| 1003 | } else { |
| 1004 | // deallocation |
| 1005 | var->second.status = allocation.status; |
| 1006 | var->second.type = allocation.type; |
| 1007 | var->second.allocTok = allocation.allocTok; |
| 1008 | } |
| 1009 | } else if (allocation.status != VarInfo::NOALLOC && allocation.status != VarInfo::OWNED && !Token::simpleMatch(tok->astTop(), "return")) { |
| 1010 | auto& allocInfo = alloctype[arg->varId()]; |
| 1011 | allocInfo.status = VarInfo::DEALLOC; |
| 1012 | allocInfo.allocTok = tok; |
| 1013 | allocInfo.type = allocation.type; |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | void CheckLeakAutoVarImpl::functionCall(const Token *tokName, const Token *tokOpeningPar, VarInfo &varInfo, const VarInfo::AllocInfo& allocation, const Library::AllocFunc* af) |
| 1018 | { |
nothing calls this directly
no test coverage detected