File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -343,7 +343,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f
343343 return No;
344344 const Token* tok = tok2->astOperand1 ();
345345 if (Token::Match (tok, " .|::" ))
346- tok = tok->astOperand2 ();
346+ tok = tok->astOperand2 () ? tok-> astOperand2 () : tok-> astOperand1 () ;
347347 varid = tok->varId ();
348348 break ;
349349 }
Original file line number Diff line number Diff line change @@ -362,6 +362,7 @@ class TestMemleakInFunction : public TestFixture {
362362
363363 TEST_CASE (gnucfg);
364364 TEST_CASE (trac3991);
365+ TEST_CASE (crash);
365366 }
366367
367368 std::string getcode (const char code[], const char varname[], bool classfunc=false ) {
@@ -3893,6 +3894,24 @@ class TestMemleakInFunction : public TestFixture {
38933894 " }" , true );
38943895 ASSERT_EQUALS (" " , errout.str ());
38953896 }
3897+
3898+ void crash () {
3899+ check (" class ComponentDC {\n "
3900+ " ::Component * getComponent();\n "
3901+ " };\n "
3902+ " ::Component * ComponentDC::getComponent() {\n "
3903+ " return ((::Component *)myComponent);\n "
3904+ " }\n "
3905+ " class MultiComponentDC : public ComponentDC {\n "
3906+ " virtual void addChild(InterfaceNode *);\n "
3907+ " };\n "
3908+ " void MultiComponentDC::addChild(InterfaceNode *childNode) {\n "
3909+ " ComponentDC *cdc = dynamic_cast<ComponentDC *>(childNode);\n "
3910+ " if (cdc)\n "
3911+ " ::Component *c = cdc->getComponent();\n "
3912+ " }" );
3913+ ASSERT_EQUALS (" " , errout.str ());
3914+ }
38963915};
38973916
38983917REGISTER_TEST (TestMemleakInFunction)
You can’t perform that action at this time.
0 commit comments