Hi,
Have been struggling to find the reason for this occasional problem with pointers that I am storing in a list (STL C++).
My class name is : Tamper
All I do is this:
1- Instantiate Tamper with new and push the address in a list of type Tamper. The number of pushes are huge, may be in hundreds (dont think it matters as long as i have space).
Tamper *ptr=new Tamper();
list<Tamper *> = mylist;
mylist.push_bac k(ptr);
2- At a later point, I simply use list iterators and retrieve the stored pointers and call "delete" on them, which sounds straight forward and it works fine for me. But once in a while, I see that my process dumps core with SIGSEGV or SIGBUS, and stack points to "delete" operation.
list<Tamper *>::iterator it = mylist.begin();
for(; it != mylist.end() ; ++it)
{
delete *it;
*it=0;
}
How do I get rid of this occasional but consistent problem while freeing the memory. I don't think I am trying to release someone else's memory.
Appreciate your help here.
Have been struggling to find the reason for this occasional problem with pointers that I am storing in a list (STL C++).
My class name is : Tamper
All I do is this:
1- Instantiate Tamper with new and push the address in a list of type Tamper. The number of pushes are huge, may be in hundreds (dont think it matters as long as i have space).
Tamper *ptr=new Tamper();
list<Tamper *> = mylist;
mylist.push_bac k(ptr);
2- At a later point, I simply use list iterators and retrieve the stored pointers and call "delete" on them, which sounds straight forward and it works fine for me. But once in a while, I see that my process dumps core with SIGSEGV or SIGBUS, and stack points to "delete" operation.
list<Tamper *>::iterator it = mylist.begin();
for(; it != mylist.end() ; ++it)
{
delete *it;
*it=0;
}
How do I get rid of this occasional but consistent problem while freeing the memory. I don't think I am trying to release someone else's memory.
Appreciate your help here.
Comment