There are several ways to find errant memory allocation.
One of the trivial ones is to replace the memory allocation and freeing
routines with a macro. For simplicity I’m using malloc and free here.
— File: Mymem.h
#define malloc(x) myMalloc(x, LINE, FILE)
#define free(x) myFree(x, LINE, FILE)
–File: Mymem.c
struct memAccount {
struct memAccount *link;
char *who;
long where;
size_t size;
};
static struct memAccount *list = NULL;
void *myMalloc(size_t size, long line, char *file)
{
struct memAccount *p;
p = malloc(size + sizeof(struct memAccount));
if (p == NULL) return NULL; // You may want to have a
warning/error here.
p->who = file;
p->where = line;
p->link = list;
p->size = size;
list = p;
return (void *)&p[1];
}
void myFree(void *p)
{
struct memAccount *pp;
struct memAccount *q, *qq;
pp = (struct memAccount *)p;
pp–; // move back one struct-size.
for(qq = NULL, q = list; q; qq = q, q = q->link)
{
if (q == pp)
break;
}
if (q != pp)
{
/// Big ERROR. Someone tried to free memory that we don’t know
of…
return;
}
if (qq) // Something before this link.
{
qq->link = pp->link;
}
else
{
list = pp->link;
}
free(pp);
}
void ListAllocatedMemory(void)
{
struct memAccount *p;
for(p = list; p; p = p->link)
{
printf(“Memory at %p of %d bytes allocated from %s:%d”, &p[1],
p->size, p->who, p->where);
}
}
If you call ListAllocatedMemory at times, you can see what is allocated.
It’s obviously best to do this when you think the number of allocations are
low.
The above code is just hacked into this mail, so it will probably not
compile… But I think it’s good enough to show the principle.
–
Mats
xxxxx@lists.osr.com wrote on 04/21/2005 12:13:02 PM:
Dear all,
I am doing HCT on my USB driver.
In driver verifier test, I got error and dumped memory.dmp file.
I analyzed this memory.dmp with dumpchk tool.
With this dump, I found that, I am not freeing one non-paged memory
allocation (BugCheckParameter4 is 1).
Is there any way to found which function is allocating this memory?
And what is the address of this memory?
Bottom I am attaching the dump analysis.
Regards,
RD
DUMP_HEADER32:
MajorVersion 0000000f
MinorVersion 00000a28
DirectoryTableBase 002ec000
PfnDataBase 81000000
PsLoadedModuleList 805531a0
PsActiveProcessHead 80559258
MachineImageType 0000014c
NumberProcessors 00000001
BugCheckCode 000000c4
BugCheckParameter1 00000060
BugCheckParameter2 00000000
BugCheckParameter3 00000020
BugCheckParameter4 00000001
PaeEnabled 00000001
KdDebuggerDataBlock 80544ce0
Questions? First check the Kernel Driver FAQ at http://www.
osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com
ForwardSourceID:NT00011252