Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Debug assertion failed in dbgheap.c

517 views
Skip to first unread message

Laurits Petersen

unread,
Dec 9, 2001, 2:48:08 PM12/9/01
to
Hi everybody!
I have a problem that only occurs when I try to compile in Visual Studio -
there is no problem compiling the code in with a Borland compiler.

One line makes my program exit with an assertion error:

Debug assertion failed in dbgheap.c

Program: myprogram.exe

File: dbgheap.c

Line: 1044

Expression: _CrtIsValidHeapPointer(pUserData)

What I've got is this:

myprogram.exe calling mydll.dll. mydll.dll contains of more files including
this code:

File 1: (c-file)

// Critical sections for secure access of global variables

HANDLE MutexComPort = NULL;

HANDLE MutexTransmitQ = NULL;

HANDLE MutexRxQ = NULL;

HANDLE MutexProtState = NULL;

HANDLE EventTransmitQFilled = NULL;

HANDLE EventRxQFilled = NULL;

HANDLE EventConnected = NULL;

File 1 (header)

extern HANDLE MutexTransmitQ

extern HANDLE MutexComPort;

extern HANDLE MutexRxQ;

extern HANDLE MutexProtState;

extern HANDLE EventTransmitQFilled;

extern HANDLE EventRxQFilled;

extern HANDLE EventConnected;

File 2:

In a init-function:

if ((EventConnected = CreateEvent((LPSECURITY_ATTRIBUTES) NULL,
TRUE, // flag for manual-reset event

FALSE, // flag for initial state

NULL // pointer to event-object name

)) == NULL) {

return 34; // Error creating Connected indicator
event

}

SetEvent(EventConnected);

In a termination-function

ResetEvent(EventConnected);

Or

CloseHandle(EventConnected);

And even

EventConnected=NULL;

I can reset and close the other events without any problems but if I reset
or close the EventConnected my program fails. I can reset the EventConnected
only if it will be set again in the next line! Anybody got any idea?

Both my exe and my dll are build in debug-mode, I've only got one dll, I'm
compiling both the exe and the dll using shared MFC in a shared dll (but
have also tried to compile without using MFC)!

Hope anybody can help me because I've spend a LOT of time trying to solve
this problem!

/Laurits


Bruce Dawson

unread,
Dec 9, 2001, 4:06:41 PM12/9/01
to
1) Run your program under the debugger.
2) When the asserts triggers, click on retry to drop into the debugger.
3) Look at the call stack to see where in your code you are calling the heap
function that is reporting the problem.
4) Think long and hard about what the assert could mean, and how you
could be causing it.

The assert is telling you that there is something wrong with your program.
You have done something illegal and, rather than silently continuing, the
C run time is loudly telling you about the problem. This is very nice.

Since it is saying that pUserData is not a valid heap pointer, that probably
means that you are passing in a bad value to free, realloc or delete. Maybe you
are freeing memory twice, or maybe you have an uninitialized pointer that
you are calling free, realloc or delete on.

You also need to double and triple check that your DLL and executable are
using the same versions of the C run time. If they aren't then you will get
this error if you allocate memory in (for instance) the executable and then
free it in the DLL.

Laurits Petersen

unread,
Dec 10, 2001, 10:52:43 AM12/10/01
to
Hi Bruce,
Tnx for your answer! You were right about free'ing memory was my problem,
but the "call stack" lead me into a wrong file (without any errors - that
was what confused me!). So I went through all my files in my project and
out-commented all the free-statements, put one after another back until the
program crashed again. Took me some hours but my program works now :-)
/Laurits

"Bruce Dawson" <comm...@cygnus-software.com> skrev i en meddelelse
news:3C13D261...@cygnus-software.com...

0 new messages