Catching delete of a stack object?
Are there tools to catches deletion of a stack object, how likely that gcc and Visual Studio de开发者_如何学运维bug build will break on that event immediately?
I deal with big, old projects, so that is not a question on how to write code, but how to detect and fix problems.
Most of the heap implementations are not tolerate to invalid pointers (i.e. when you delete
an address which was not returned to you by the heap). Almost for sure standard windows heap, and CRT's heap (implemented by MSVC) cause a debug breakpoint in such a case.
You may also replace the implementation of new
/delete
operators and do the checking yourself (in your case you only want to check if the address belongs to the stack memory, which is easy).
It's very unlikely that such a thing would happen if you design the ownerships in advance and use smart pointers to enforce them if necessary. I doubt that they'll do anything but throw on a generic bad deallocation.
精彩评论