File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -735,17 +735,24 @@ void CheckMemoryLeakStructMember::check()
735735 }
736736}
737737
738- bool CheckMemoryLeakStructMember::isMalloc (const Variable * variable) const
738+ bool CheckMemoryLeakStructMember::isMalloc (const Variable* variable) const
739739{
740740 if (!variable)
741741 return false ;
742742 const int declarationId (variable->declarationId ());
743743 bool alloc = false ;
744- for (const Token * tok2 = variable->nameToken (); tok2 && tok2 != variable->scope ()->bodyEnd ; tok2 = tok2->next ()) {
744+ for (const Token* tok2 = variable->nameToken (); tok2 && tok2 != variable->scope ()->bodyEnd ; tok2 = tok2->next ()) {
745745 if (Token::Match (tok2, " = %varid% [;=]" , declarationId))
746746 return false ;
747- if (Token::Match (tok2, " %varid% = %name% (" , declarationId) && mSettings ->library .getAllocFuncInfo (tok2->tokAt (2 )))
748- alloc = true ;
747+ if (Token::Match (tok2, " %varid% =" , declarationId)) {
748+ const Token* tok3 = tok2->tokAt (1 )->astOperand2 ();
749+ while (tok3 && tok3->isCast ())
750+ tok3 = tok3->astOperand2 () ? tok3->astOperand2 () : tok3->astOperand1 ();
751+ if ((tok3 && Token::Match (tok3->tokAt (-1 ), " %name% (" ) && mSettings ->library .getAllocFuncInfo (tok3->tokAt (-1 ))) ||
752+ (Token::simpleMatch (tok3, " new" ) && tok3->isCpp ()) {
753+ alloc = true ;
754+ }
755+ }
749756 }
750757 return alloc;
751758}
You can’t perform that action at this time.
0 commit comments