Debug Assertion Failed Error

Hi All,

i have written an dll in Vc++ 6.0. basically it is multithreaded application.
The application is writing log in text files using (WriteFile Function) at various locations.
i am getting an error after continuos running of 7 - 8 hours

' Debug Assertion Failed'
file -> dbgheap.c
line no -> 1017

if i comment the log functions, there is no error.

Kindly suggest me what should i do?
[463 byte] By [Munish.Coraltele] at [2007-11-20 8:54:22]
# 1 Re: Debug Assertion Failed Error
Check your log functions. Most likely you write outside a sprintf buffer.
S_M_A at 2007-11-10 3:03:08 >
# 2 Re: Debug Assertion Failed Error
I agree with S_M_A, in the sens of type of bug._ASSERTE(_BLOCK_TYPE_IS_VALID(pHead->nBlockUse));This assertion fails most likely because of a memory corruption. A buffer overrun is a common scenario, but can be also a thread syncronization problem. When the assertion fails, load the application into debugger and check first how the callstack looks like and which thread fails to free memory. It should help finding the statement which tries to discard the corrupted / already discarded buffer. Considering the multithreaded environment in which is running, review the syncronization for those kind of shared allocations. If the faulty code is within the method of a class, inspect the instance for which the crash occurs... might be an instance previously freed by another thread. You know best how your code is supposed to behave, so try to see what doesn't look wright.
If you found the type of object for which the assertion fails, a simple method exists to find the reason. Insert a signature DWORD as first member data of that class, which gets initialized in every constructor with, lets say 0x0B0A9776 ^ (DWORD)this. In the destructor, replace the value of the signature with, les say 0x13377B0A ^ (DWORD)this, marking the memory of the object as "deleted". The first thing that you should do in the destructor is to check if the signature matches the value assigned in the constructor. If not, means the instance should not be deleted, and to know if was already deleted, test the signature value for the value that your destructor is setting. If the an object is deleted twice from different threads because of a syncronization problem, that usually occurs almost immediatelly, thus you should see a signature of a deleted object, because it is unlikely that another memory allocation took place on an overlapping memory. If the signature value is sort of bogus (none of the 2 your code is doing), then most likely your code is corrupting the memory through some sort of buffer overrun.
Hope it will help in finding your bug.
All the best,
Bornish at 2007-11-10 3:04:11 >
# 3 Re: Debug Assertion Failed Error
Sometimes i get an debug assertion when there are still watches , for example on pointers form an erlier debug session, already has lost a lot time because of this...
Smetje at 2007-11-10 3:05:10 >
# 4 Re: Debug Assertion Failed Error
You can be sure that debugger is not causing any asserts in your code.

As said before, the most likely origin is that your log function writes outside a buffer. Add your own assert to verify that the log function behaves as expected and run in debugger again. When/if your assert kicks in use debugger and call stack to find out why.
S_M_A at 2007-11-10 3:06:12 >
# 5 Re: Debug Assertion Failed Error
Also I wonder why ANYONE would think this is a bug in Visual C++ :confused: :confused: :confused:

Debug Assertions are deliberate parts of the system designed to identify problems in the programmers code.....
TheCPUWizard at 2007-11-10 3:07:11 >