Friday, June 15, 2007

Recursive Destruction and Stack Overflow

Here's something stupid for C++. I was testing an algorithm using a trie implemented by std::list on some data today, which resulted in a very deep tree. At exit the program crashed, due to recursive destruction: std::list destroyed all its elements, which were also tries. There is a similar vulnerability in PHP, though they use C rather than C++. I'm still wondering how to do this in C++. Pool design may be much better in such cases, especially for parse trees. I think I have discussed this with Nirvana when we were implementing a bencode parser several months ago.

No comments: