Exception handling and heap corruption

Discussion in 'C++' started by Riley DeWiley, Jun 25, 2005.

  1. 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
     
    Riley DeWiley, Jun 25, 2005
    #1
    1. Advertising

  2. Riley DeWiley

    Alan Johnson Guest

    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
     
    Alan Johnson, Jun 25, 2005
    #2
    1. Advertising

  3. Riley DeWiley

    Jim Langston Guest

    "Alan Johnson" <_edu> wrote in message
    news:d9isg1$l87$...
    > 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.
     
    Jim Langston, Jun 27, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    3,840
    Walter
    Apr 29, 2005
  2. Walter Roberson

    My MSVC 6 DLL now has HEAP corruption problems

    Walter Roberson, May 11, 2005, in forum: C Programming
    Replies:
    2
    Views:
    466
    Flash Gordon
    May 12, 2005
  3. Martin the Third
    Replies:
    8
    Views:
    393
    Kai-Uwe Bux
    Jun 13, 2008
  4. finding83

    heap corruption

    finding83, Jul 30, 2009, in forum: C++
    Replies:
    6
    Views:
    609
    James Kanze
    Jul 31, 2009
  5. mohangupta13

    cause of heap corruption here??

    mohangupta13, Sep 12, 2009, in forum: C Programming
    Replies:
    3
    Views:
    393
    Barry Schwarz
    Sep 13, 2009
Loading...

Share This Page