I don’t know if this question will be clear, since I cannot give too many details (I use TPL and wrote a huge number of lines myself). But I'll try.
I am experiencing a segmentation error that I cannot understand. There is a structure (which I did not develop, but should be well tested), whose destructor is as follows
Data::~Data() { if(A_ != 0) { delete A_; A_ = 0; } if(B_ != 0) { delete B_; B_ = 0; } if(C_ != 0) { delete C_; C_ = 0; } }
What bothers me is that when debugging, I get that segfault happens on the line marked “HERE”. The Data class has only A_, B_, and C_ as dynamically allocated attributes. I also tried to explicitly call the destructor on other non-dynamic compound attributes to make sure that something went wrong during their destruction, but again segfault happens at the end of the destructor. What errors can segfault give at this moment ?.
I hope that the question will be clear enough, I will add details if necessary.
Edit: thanks for the answers. I know that this is a damn piece of code, but the whole library is, of course, too large (by the way, it is from Trilinos, but I think that the error is not their fault, it must be my mistake in working with their structures. Short names to make the problem more compact). Some comments that someone asked in the comments:
In conclusion, let me repeat my doubt: what errors can appear in the END of the destructor, even if ALL attributes have already been deleted? Thanks again!
bartgol
source share