473,326 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Exception handling and heap corruption

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
Jul 23 '05 #1
2 4684
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
Jul 23 '05 #2
"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.
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steffen | last post by:
I'm searching for a heap monitoring tool, 'cause I have a heap crash in my software (c++). It occurs only after some days running my program. The crash happens by allocating string-buffers deep in...
2
by: Robert Oschler | last post by:
Need help with HEAP CORRUPTION and my MSVC 6 DLL I have a MSVC 6 DLL that I've written. It is used heavily by a Delphi 6 app I've written. For two months everything has been working fine. ...
13
by: tolisss | last post by:
Hi i have setup a global exception handler b4 Application.Run like Application.ThreadException += new ThreadExceptionEventHandler(GlobalExceptionProcessing.AppThreadException ); then after...
5
by: Peter Steele | last post by:
We have an application that when it runs in the IDE in debug mode an unhandled exception is occurring in a system header file associated with STL stirngs. The actual statement that crashes is ...
3
by: doubts | last post by:
Hi all, I am trying to convert my bulk of code from VC++ 6.0 to VC++.Net. when using std::string type variable, the application causes exception at one instance and does not cause an exception at...
1
by: Vasuki | last post by:
Hi My application crashes all of a sudden giving me the following error. Can anybody help please? Exception code: C0000005 ACCESS_VIOLATION Fault address: 77FCE005 03:00002005...
14
by: jehugaleahsa | last post by:
Hello: As an avid reader of C++ books, I know a lot of programmers out there are confronted with the challenge of exception safety. For those who don't know what it is, it is writing code in...
6
by: George2 | last post by:
Hello everyone, Suppose I have some objects created on local function stack (not on heap). And I allocate and free all the related resources in the constructor and destructor (e.g. memory and...
8
by: Martin the Third | last post by:
Hi, I need some help! I'm writing an infinite-precision floating point library called ipfloat (I know infinite is a misnomer - but arbitrary was taken). A quick overview: I'm storing numbers as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.