Discussion:
DAMAGE: after normal block.. - heap error in Debug
(too old to reply)
Krzysztof Klimczak
2004-01-04 11:51:03 UTC
Permalink
Hi all,

I have a simple code like this:

CString lpszSection;
CString lpszEntry;
UINT Bytes;
BYTE *pData = NULL;

if (!GetProfileBinary((LPCTSTR)lpszSection, lpszEntry,
&pData, &Bytes)) {
..
}
...
if ( pData )
delete [] pData;

The last line (delete []) in Debug build causes the
error:
DAMAGE: after normal block (#xxx) at 0x0....

After debug I found that the error is generated in
dbgheap.c module at line 1150.

After choosing continue another dialog appears saying:
Unhandled exception at 0x1... (msvcr71d.dll) in x.exe:
User breakpoint.
And then the program continues normally till next time
the code is executed.

The pData contains always 14 bytes of data, here is the
sample:
Data: <20040104004950> 32 30 30 34 30 31 30 34 30 30 34
39 35 30

For me it seems like bug in the heap handling in Debug
mode. The same happened when I used the VC++ 6.
Does anybody have an idea how to fix it?

The error does not appear in the Release build.

Regards,
Krzysztof
Scott McPhillips [MVP]
2004-01-04 16:11:34 UTC
Permalink
Post by Krzysztof Klimczak
Hi all,
CString lpszSection;
CString lpszEntry;
UINT Bytes;
BYTE *pData = NULL;
if (!GetProfileBinary((LPCTSTR)lpszSection, lpszEntry,
&pData, &Bytes)) {
..
}
...
if ( pData )
delete [] pData;
The last line (delete []) in Debug build causes the
DAMAGE: after normal block (#xxx) at 0x0....
...
The error does not appear in the Release build.
Regards,
Krzysztof
The code that you show looks good. Try commenting out all your other
code (the ... part) that processes the data to see if this eliminates
the problem. The returned data is not null terminated, so if you use
any string functions to process the data those functions will corrupt
the memory beyond.

The error does not appear in the release build because only the debug
build checks for heap corruption. The results in a release build are
undefined. Something else gets corrupted :)
--
Scott McPhillips [VC++ MVP]
Krzysztof Klimczak
2004-01-04 21:13:21 UTC
Permalink
-----Original Message-----
Post by Krzysztof Klimczak
Hi all,
CString lpszSection;
CString lpszEntry;
UINT Bytes;
BYTE *pData = NULL;
if (!GetProfileBinary((LPCTSTR)lpszSection, lpszEntry,
&pData, &Bytes)) {
..
}
...
if ( pData )
delete [] pData;
The last line (delete []) in Debug build causes the
DAMAGE: after normal block (#xxx) at 0x0....
...
The error does not appear in the Release build.
Regards,
Krzysztof
The code that you show looks good. Try commenting out
all your other
code (the ... part) that processes the data to see if
this eliminates
the problem. The returned data is not null terminated,
so if you use
any string functions to process the data those functions
will corrupt
the memory beyond.
The error does not appear in the release build because
only the debug
build checks for heap corruption. The results in a
release build are
undefined. Something else gets corrupted :)
--
Scott McPhillips [VC++ MVP]
I do not use any string related functions but before I
write the binary data to registry I convert it from
string and I forget to write terminating NULL !!!
After reading it in binary I convert it to string again
and I ... add automatically terminating NULL which means
I overwrite first not my byte on the heap. So debug was
right...
Now it works fine - I write an additional byte to the
registry key destined for NULL.

Many thanks for your answer which allowed me to find the
bug.

Regards,
Krzysztof Klimczak

Loading...