Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Exception handling and heap corruption

Reply
Thread Tools

Exception handling and heap corruption

 
 
Riley DeWiley
Guest
Posts: n/a
 
      06-25-2005
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


 
Reply With Quote
 
 
 
 
Alan Johnson
Guest
Posts: n/a
 
      06-25-2005
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
 
Reply With Quote
 
 
 
 
Jim Langston
Guest
Posts: n/a
 
      06-27-2005
"Alan Johnson" <(E-Mail Removed)_edu> wrote in message
news:d9isg1$l87$(E-Mail Removed)...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
heap corruption finding83 C++ 6 07-31-2009 08:08 AM
Heap overflow/corruption problem in an arbitrary precision class Martin the Third C++ 8 06-13-2008 07:47 PM
My MSVC 6 DLL now has HEAP corruption problems Walter Roberson C Programming 2 05-12-2005 08:32 AM
Tools For Heap Corruption nsyforce@aol.com C++ 2 04-29-2005 12:18 AM
iDEFENSE Security Advisory 02.28.05: Mozilla Firefox and,MozillaBrowser Out Of Memory Heap Corruption Design Error winged Computer Security 1 03-02-2005 01:56 AM



Advertisments