Solved

Debug Assertion Fail (MSVC++ 4.2)

Posted on 1997-03-04
1
1,568 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 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