473,671 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

My MSVC 6 DLL now has HEAP corruption problems

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
Nov 14 '05 #1
2 2630
In article <Z8************ ********@adelph ia.com>,
Robert Oschler <no************ @nospam.com> 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.
Nov 14 '05 #2
Walter Roberson wrote:
In article <Z8************ ********@adelph ia.com>,
Robert Oschler <no************ @nospam.com> 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.
Nov 14 '05 #3

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

Similar topics

3
2504
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 the mfc. Any ideas where i can find such tool? Steffen
2
4711
by: Riley DeWiley | last post by:
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, can I use the try/except mechanism to trap heap corruption? How can I recover? It is easy enough to do this: try
26
2668
by: jamesbeswick | last post by:
I've been using Access since version 97 and I've migrated to 2003. I've noticed a substantial number of strange ActiveX/OLE and code corruption problems when writing databases. The only solution I've found is to create a new database and import all the objects from the corrupted file. Has anyone else found a solution to this annoying problem? I cannot find anything useful on Microsoft's website and I haven't seen any posts about the...
9
2657
by: William L. Bahn | last post by:
I am having a strange problem - and I suspect it is something specific to my compiler - but want to get a read on the Standard C portion of it first. Basic Question: Under the C Standard, under what conditions, if any, can a value returned by malloc() not be used in a subsequent free() call? I have a program that does a lot of things. I don't have the code handy to post, but I think a word description will do. I'd be
11
9068
by: Florian A. | last post by:
Hi everyone! I'm trying to write a global hook in C# and C++/CLI. I'm almost done if there wasn't this little delegate problem. I get the function pointer to a delegate and pass it to my hook.dll. The delegate gets called for a few seconds but then the delegate seems to be relocated on the CLR heap. If tried using a GCHandle but as far as I can tell this only prevents the garbage collector from collecting my delegate and doesn't stop...
1
1671
by: syntheticpp | last post by:
Here a compiler bug of msvc 8 (14.00.50727.42): fatal error C1060: compiler is out of heap space Without the virtual inheritance it compiles fine. GCC has no problems. Code (tested with Loki 0.1.3):
23
2559
by: Dave G | last post by:
Since upgrading one of my clients from A97/W2000 to A2003/XP they have suffered no end of data corruption problems, mainly involving one of the main tables. The corruption can result in one record's fields turning into chinese characters. On running the compact/repair I can see that the corruption may be deeper than I expected because sometimes indexes are missing and need to be replaced. I used to think that overuse of 'ctrl-alt-delete'...
9
2925
by: Arsalan Ahmad | last post by:
Hi all, I have developed a static library which I am using in one of my application. In my library I have created my own heap and all the objects (class objects) in my application are created in that heap. What I have observed is that in my library at a certain place when I call EnterCriticalSection() to an object allocated at my heap, it is corrupting my heap. I am using Windows XP and visual studio 8.0. Any hint how can I solve this...
8
2076
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 a char* mantissa, an int exponent and a sign. For example, the number "123.45" would have a mantissa of 12345, an exponent of 2, and a sign of +. I'm essentially storing it as "1.2345x10^2". The mantissa is allocated dynamically at runtime to...
0
8392
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8912
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8597
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8669
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2809
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1807
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.