[googlemock: 781] gmock reports incorrect leak

1,934 views
Skip to first unread message

blah blah

unread,
Apr 20, 2010, 4:37:07 PM4/20/10
to Google C++ Mocking Framework
Hi,

I am trying to use gmock in a simple sample that has a MyShapeUser
class that takes over the ownership of DI passed in pointer of
shapemock. it frees it. but Googlemock returns me an error saying
"\myshapeusertest.cpp(23): ERROR: this mock object should be deleted
but never is. Its address is @001FF450.
ERROR: 1 leaked mock object found at program exit."

ShapeMock* pshapemock = new ShapeMock();
EXPECT_CALL(*pshapemock, Area())
.Times(1)
.WillOnce(Return(5));

{
MyShapeUser *p = new MyShapeUser ( pshapemock);
delete p; // the destructor cleans up
}

I have checked with windbg, i have stepped through the code and can
see that the pshapemock was deleted correctly. why is google mock
complaining? Am I missing something?




--
Subscription settings: http://groups.google.com/group/googlemock/subscribe?hl=en

Zhanyong Wan (λx.x x)

unread,
Apr 20, 2010, 4:40:02 PM4/20/10
to blah blah, Google C++ Mocking Framework

blah blah

unread,
Apr 20, 2010, 6:09:59 PM4/20/10
to Google C++ Mocking Framework
hmm.. that does fix it.. you are right.. i did not have a virtual
destructor..

so a workaround to use testing::Mock::AllowLeak(shapemock); was a
really bad choice..

On Apr 21, 6:40 am, Zhanyong Wan (λx.x x) <w...@google.com> wrote:
> Does this help?
>
> http://code.google.com/p/googlemock/wiki/FrequentlyAskedQuestions#I_g...
>
>
>
>
>
> On Tue, Apr 20, 2010 at 1:37 PM, blah blah <sras...@gmail.com> wrote:
> > Hi,
>
> > I am trying to use gmock in a simple sample that has a MyShapeUser
> > class that takes over the ownership of DI passed in pointer of
> > shapemock. it frees it. but Googlemock returns me an error saying
> > "\myshapeusertest.cpp(23): ERROR: this mock object should be deleted
> > but never is. Its address is @001FF450.
> > ERROR: 1 leaked mock object found at program exit."
>
> >                 ShapeMock* pshapemock = new ShapeMock();
> >        EXPECT_CALL(*pshapemock, Area())
> >                .Times(1)
> >                .WillOnce(Return(5));
>
> >        {
> >                MyShapeUser *p = new MyShapeUser ( pshapemock);
> >                delete p; // the destructor cleans up
> >        }
>
> > I have checked with windbg, i have stepped through the code and can
> > see that the pshapemock was deleted correctly. why is google mock
> > complaining? Am I missing something?
>
> > --
> > Subscription settings:http://groups.google.com/group/googlemock/subscribe?hl=en
>
> --
> Zhanyong- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages