Reputation: 22342
I have a vector<vector<Person*>*>*
called groups (yes, I know about shared_ptr, but I can't use them in this context), and another one called partialGroups
Anyway, at the end of the method I delete all of the inner vector's, but not the people themselves, because I still want them to be valid, so here is the end of the code:
// Deal with remaining partial teams
vector<Person*> *unsortable;
groups->push_back(unsortable);
// Remaining people
for(unsigned int i = 0; i < people.size(); i++) {
unsortable->push_back(people[i]);
}
// Remaining partial groups
for(unsigned int i = 0; i < partialGroups.size();i++) {
for(unsigned int j = 0; j < partialGroups[i]->size(); j++) {
unsortable->push_back(partialGroups[i]->at(j));
}
delete partialGroups[i];
}
return groups;
I then call the method with this line of code:
vector<vector<Person*>*> *currentMatch = sort(*people);
I can run gdb all th way to the return groups; statement, and looking at the data structure, it is just fine. However, when I step out of the method, the program crashes, and the stack trace shows that it's crashing in the vector destructor itself.
What on earth could cause this? It shouldn't be a problem with the Person destructor as the inner vector is of pointers to people. Also, taking out the delete line does not make a difference. (Yes, I know it would leave a memory leak, but it might have helped to diagnose the problem).
Thank you.
edit: Also, the error is a sigabrt
Upvotes: 0
Views: 2059
Reputation: 11522
If this code snippet is accurate, you're doing all kinds of things with an uninitialized pointer, unsortable
. I'm surprised it gets as far as the exit from the method.
Upvotes: 6