"Alan Johnson" <al****@stanford.dot.nospam_edu> wrote in message
news:d9**********@news.Stanford.EDU...
Riley DeWiley wrote: I have a program which must call into third party code that might do a
wild write (I have been getting ASSERTs and access violations in debug
code when I am freeing pointers after a call into that code).
Assuming I have no control over what the third party code does, [how] can
I use the try/except mechanism to trap heap corruption? How can I
recover?
It is easy enough to do this:
try
{
foo();
}
except(...)
{
//handle problems ...
recover_foo();
};
but when I get to recover_foo()
- Is my heap already thrashed?
- If so, can I recover somehow?
RDeW
Unless the third party code is actually throwing exceptions when something
goes wrong, the try/catch mechanism isn't going to do anything for you.
Any method for repairing a corrupted heap is going to depend highly on
your platform. (C++ doesn't even require that an implementation have any
such concept.)
-Alan
Only thing I could think of would be perhaps to place the library
call in it's own thread and run it. It is OS specific, but in windows
each thread gets it's own stack. So it would trash it's own stack
but not yours (hopefully). Of course then you'd have to implement
code to get get the actual return value, such as shared memory.