Hi,
I have a code,
class foo
{
public:
foo(){};
~foo(){};
};
class bar
{
public:
bar(){};
~bar(){};
foo& Foo()
{
return m_foo;
}
private:
foo m_foo;
};
int main()
{
bar *obj = new bar;
if( /* true condition here */ )
{
foo lcFoo;
lcFoo = obj->Foo(); // forgot this
}
delete obj;
}
Now I am getting a double free message from glibc when I call the "delete obj" part.
Please advice.
Thanks.
EDIT: Thanks for the comments but this is the exact code I used. Do you think the problem is in the foo& Foo() function because it return the reference of the m_foo object and then when code jump to the if condition brace then that m_foo will be deleted?