Original Post
Hello all, In an effort to find memory leaks in my code I put together my own wrappers arround malloc/free etc, to put buffer zones arround memory, log to file, keep track of how much memory is in use etc. Anyway, as part of that I use heapcheck & heapchecknode to localise any problems, the problem is any malloc over 1 meg in size is allways a bad node. To test this wasn't a side effect of my program somewhere I wrote the folowing test program: And compiled it with 'bcc32 main.cpp' It outputs: 1022: (8661496) used entry (ok) 1023: (8661496) used entry (ok) 1024: (12845060) bad node 1025: (12845060) bad node Can anyone explain it to me? I'm using the free BCC32 5.5 compiler. Thanks in advance for any inteligence beyond my own, Lethe
#include <malloc.h>
#include <alloc.h>
#include <mem.h>
#include <stdio.h>
#include <conio.h>
void testSize(int size)
{
void * tmp = malloc(size);
printf("(%i) ",(int)tmp);
int ret = heapchecknode(tmp);
switch (ret)
{
case _USEDENTRY: printf("used entry (ok)\n"); break;
case _HEAPCORRUPT: printf("heap corrupt\n"); break;
case _BADNODE: printf("bad node\n"); break;
case _BADVALUE: printf("bad value\n"); break;
case _HEAPBADBEGIN: printf("heap bad begin\n"); break;
case _HEAPBADNODE: printf("heap bad node\n"); break;
case _HEAPBADPTR: printf("heap bad ptr\n"); break;
}
free(tmp);
}
int main()
{
for (int i=1022;i<1026;i++)
{
printf("%i: ",i);
testSize(i*1024);
}
getch();
return 0;
}