Solved

MFC Debug assertion failed in release version

Posted on 1997-03-13
1
599 Views
Last Modified: 2010-05-18
I'm currently building an application that makes extensive use of the ODBC class CRecordSet of the Visual C++ MFC classes. While writing my application, I've constantly worked in the Debug mode and my program works fine. However, when I rebuilt my program in the Release mode, I got the following debug assertion:
   Debug Assertion Failed
   Program C:\.....\myprogram.exe
   file: dbgheap.c
   Line: 1017
   Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

I've traced the problem (using printf throughout my code) to the CRecordSet::Open method used to open my database.

I would like to know how my program can cause a debug assertion at all after I've compiled it in release mode. Second of all, I'd like to know how to solve this problem. Could this be a wrong build-setting, or is my own code acting up somewhere? And if so, why does my code run perfectly during a debug session?

Thanks in advance for any suggestions / solutions.

Remko

PS: I made sure to do 'Rebuild All' when rebuilding for the release version.
0
Comment
Question by:fprwy
1 Comment
 
LVL 1

Accepted Solution

by:
rhgaracci earned 100 total points
ID: 1162299
It sounds like your project settings are specifying a debug MFC library to be linked in.  MFC uses the debug heap when it allocates memory for CObject derived objects.  It sounds like the heap is being corrupted by a write to an invalid memory address.  Rebuilding the application moves everything around in memory, and so the location of the corruption can move as well, which could explain why the problem doesn't manifest itself in the debug version.

Check your code for anywhere you write to memory using a pointer.   You may have an invalid pointer somewhere.  This can easily happen when processing arrays if you overrun the boundaries.



0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now