My MSVC 6 DLL now has HEAP corruption problems

Discussion in 'C Programming' started by Walter Roberson, May 11, 2005.

  1. In article <>,
    Robert Oschler <> wrote:
    >I have a MSVC 6 DLL that I've written. It is used heavily by a Delphi 6 app
    >I've written.


    The problems you are seeing are not at all portable. DLL's and Delphi
    are not part of C, so you would get much better assistance in
    one of the Windows programming newsgroups.
    --
    Feep if you love VT-52's.
     
    Walter Roberson, May 11, 2005
    #1
    1. Advertising

  2. 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. Then I changed some things
    in the code recently, and now I'm getting what looks like severe corruption
    of the heap.

    I am wondering if it is some strange interaction between the Delphi app and
    my MSVC 6 DLL, that I somehow caused with a recent change to either of the
    programs. I say this because when I run the exact same library code that is
    "wrapped" in the DLL, in a Win32 Console test application which I created to
    test the code, it works perfectly. It is only, and only recently, when I
    run it as a DLL with the Delphi app as a client, that I see the heap
    corruption. I checked all the project settings for the dependent libraries
    my DLL links in, and my DLL project settings, and everyone is set to Debug
    Multithreaded DLL for the code generation option (and all other settings are
    the same too). I am currently testing in Win32 Debug configuration with
    gflags monitoring the process in "/full" mode.

    I say the heap is corrupted because of the following evidence:

    - There is a setup function in the DLL code where a large amount of
    calloc()'s occur in a loop. Each calloc() does one allocation of a 12 byte
    elements (i.e. 12 bytes total). Normally this only consumes a couple of
    megabytes of memory and executes fast. I traced through the calloc() calls
    and with each calloc() over 4000 bytes (4k) are being allocated!. After a
    few seconds. the memory consumption of the process as reported by the Win2k
    task manager, shoots up to almost 280 megabytes of memory. Pretty soon
    thereafter I get a "System is low on virtual memory" dialog box and finally
    all calloc() calls begin to fail. Meltdown.

    Before I ran gflags, I was getting weird access violations all over the
    place.

    As I rack my brain trying to think what I may have done recently to cause
    this, the only major change I can think of was the including of <crtdbg.h>
    in several source files that use "assert". But those includes are in IFDEF
    blocks and are not included when I build using the Win 32 release
    configuration, yet the heap corruption still occurs. This would seem to
    indicate that the <crtdbg.h> change is not a factor.

    Once more, this does not happen with the exact same code when that code is
    linked into an MSVC Win32 Console application, only when running as a DLL.

    So what can I try to do to fix this? What kind of tests can I try?

    Thanks,
    Robert
     
    Robert Oschler, May 11, 2005
    #2
    1. Advertising

  3. Walter Roberson

    Flash Gordon Guest

    Walter Roberson wrote:
    > In article <>,
    > Robert Oschler <> wrote:
    >
    >>I have a MSVC 6 DLL that I've written. It is used heavily by a Delphi 6 app
    >>I've written.

    >
    > The problems you are seeing are not at all portable. DLL's and Delphi
    > are not part of C, so you would get much better assistance in
    > one of the Windows programming newsgroups.


    The problem is almost certainly a C problem such as double freeing or
    running off the end of a buffer and nothing to do with DLLs or Delphi.

    It probably works from the console app but not from Delphi for the same
    reason any program invoking undefined behaviour "works" for a simple
    test but not when doing an important demonstration or delivery. Blind luck.

    *If* the OP can post code that does not use MS extensions, then it can
    be looked at here. Depending on what the DLL does this *might* be
    possible. If not, it will will have to be looked at in a Windows
    programming group.

    The same would apply with a shared library for *nix.

    <OT>I know through personal experience that calling DLLs written in MSVC
    from Delphi applications works as it should.</OT>
    --
    Flash Gordon
    Living in interesting times.
    Although my email address says spam, it is real and I read it.
     
    Flash Gordon, May 12, 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,850
    Walter
    Apr 29, 2005
  2. Riley DeWiley
    Replies:
    2
    Views:
    819
    Jim Langston
    Jun 27, 2005
  3. Martin the Third
    Replies:
    8
    Views:
    400
    Kai-Uwe Bux
    Jun 13, 2008
  4. finding83

    heap corruption

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

    cause of heap corruption here??

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

Share This Page