Heap corruption when a tstring is deleted or goes out of scope

Description
When a tstring goes out of scope or is deleted, the following error is reported.

HEAP[XXXX.exe]: Invalid Address specified to RtlValidateHeap( 8e0000, 8c3510 )
Unhandled exception at 0x77fa144b in Usage1.exe: User breakpoint

or

Windows has triggered a breakpoint in XXXXX.exe.
This may be due to a corruption of the heap, and indicates a bug in XXXXXX.exe or any of the DLLs it has loaded.
The output window may have more diagnostic information

The Problem
In debug, all memory allocations are tracked within the debug version of the CRT (C runtime libraries). They keep track of all the allocations, and then tick them off as there de-allocated. When you are using 2 libraries that link different versions (or instances) of the CRT, then you have 2 lists of allocated objects. This may not sound like a problem, but it is posible (and likley) that memory will be allocated against one, and de-allocated against another. It is under these sucumstances that you see this problem. More on this can be found on the Microsoft site Potential Errors Passing CRT Objects Across DLL Boundaries.

Solution

Change the way the projects are linked (See linking).

E.g. Visual Studo 6.0 - change from Debug Multithreaded (/MTd) to Debug Multithreaded DLL (/MDd):

E.g. Visual Studio .Net (version 7.0) - change from Multi-threaded Debug (/MTd) to Multi-threaded Debug DLL (/MDd):



Applies To
All Builds of Liquid XML DataBinder, when using Microsoft Visual C++ (all Versions)

Add Feedback