double free when std::list is destroyed

J

JustSomeGuy

I think that I have a memory leak / free problem.

I have object that I put into a std::list.

When the list is destroyed I think the objects in the list are also
destroyed.
However they are not refrences to objects they are actual deep copies
of
objects in the list. So it should be ok to delete them when the list
is deleted
and then the original objects will be deleted when they go out of
scope...

Any suggestions on how to find this double free?
 
B

Ben Pope

JustSomeGuy said:
I think that I have a memory leak / free problem.

I have object that I put into a std::list.

When the list is destroyed I think the objects in the list are also
destroyed. However they are not refrences to objects they are actual
deep copies of objects in the list. So it should be ok to delete
them when the list is deleted and then the original objects will be
deleted when they go out of scope...

Any suggestions on how to find this double free?

Well it's not in the code you have talked about, unless the copy
constructor or assignment operator of your "object" is FUBAR.

Does your "object" allocate resources?

Ben Pope
 
T

TB

JustSomeGuy skrev:
I think that I have a memory leak / free problem.

Really?

I have object that I put into a std::list.

When the list is destroyed I think the objects in the list are also
destroyed.
However they are not refrences to objects they are actual deep copies
of
objects in the list. So it should be ok to delete them when the list
is deleted
and then the original objects will be deleted when they go out of
scope...

Any suggestions on how to find this double free?

For each new/new[] there should exist a delete/delete[].
If you don't allocate it with new/new[], then you don't have
to worry, there is no leakage.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top