Solved

Debug Assertion Fail (MSVC++ 4.2)

Posted on 1997-03-04
1
1,557 Views
Last Modified: 2013-12-03
Hi!

I have a following problem:
When I allocate something in DLL and then I deallocate it
in application I get assertion failure:

Debug Assertion Failed!
File: dbgheap.c
Line: 1076
Expression: _pFirstBlock == pHead

I'm using VC++ 4.2 / Window95.

Simple demonstration of the problem:
===========================
DLL code:
---------------
__declspec( dllexport ) int* AllocInt()
{
      return new int;
}

Application code:
-------------------------
__declspec( dllimport) int* AllocInt();

void main()
{
    int* i;
    i = AllocInt();
    delete i;  // causes an assertion failure
}

Thanks for help
            Zdenek

---------------------------------------------
Zdenek Zemanek
<zemanek@cit.cdrail.cz>
---------------------------------------------
0
Comment
Question by:zdenekzz
1 Comment
 
LVL 1

Accepted Solution

by:
gvg earned 100 total points
ID: 1298720
Here is my guess.  
If you look at line 85 in dbgheap.c you can see that _pFirstBlock is
a static variable in dbgheap.c.  Now if your DLL is compiled in
a release version in witch case it doesn't use dbgheap.c the _pFirstBlock
variable in dbgheap.c will not be right when you use debug delete.

In short.  You are using Release new while using Debug delete.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question