File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1022,10 +1022,8 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope)
10221022 const Token* tok2 = tok->next ()->astParent ();
10231023 while (tok2 && (tok2->isCast () || Token::Match (tok2, " ?|:" )))
10241024 tok2 = tok2->astParent ();
1025- if (Token::Match (tok2, " %assign%" )) // TODO: check if function returns allocated resource
1026- continue ;
1027- if (Token::simpleMatch (tok->astTop (), " return" ))
1028- continue ;
1025+ const bool hasAssign = Token::Match (tok2, " %assign%" );
1026+ const bool hasReturn = Token::simpleMatch (tok->astTop (), " return" );
10291027
10301028 const std::string& functionName = tok->str ();
10311029 if ((tok->isCpp () && functionName == " delete" ) ||
@@ -1037,6 +1035,12 @@ void CheckMemoryLeakNoVar::checkForUnreleasedInputArgument(const Scope *scope)
10371035 if (!tok->isKeyword () && !tok->function () && !mSettings ->library .isLeakIgnore (functionName))
10381036 continue ;
10391037
1038+ if ((hasAssign || hasReturn) && !tok->function ()) {
1039+ const std::string& ret = mSettings ->library .returnValueType (tok);
1040+ if (ret.empty () || endsWith (ret, " *" ))
1041+ continue ;
1042+ }
1043+
10401044 const std::vector<const Token *> args = getArguments (tok);
10411045 int argnr = -1 ;
10421046 for (const Token* arg : args) {
You can’t perform that action at this time.
0 commit comments