Hi,
I am de-allocating memory for a structure(and its buffers) that where allocated beforehand but crash happens when i am doing trying to do this.
After some testing i noticed that when i deallocate the structers by getting the pointer to the structures from an entry list its crashing but when i use the pointer that they where created with it works fine.
here is the code:
//Allocation
NdisAllocateMemoryWithTag(&pPacket, sizeof(PACKET),‘oiuN’)
NdisAllocateMemoryWithTag(&pPacket->aStructA,LookaheadBufferSize, ‘oiuN’);
NdisAllocateMemoryWithTag(&pPacket->aStructA,HeaderBufferSize, ‘oiuN’);
//De-allocation code
pEnt = RemoveHeadList(&masterstruct->Packets);
IP = (PPACKET) pEnt;
if(IP!=NULL)
{
NdisFreeMemory(IP->aStructA,0,0);
NdisFreeMemory(IP->aStructB,0,0);
NdisFreeMemory(IP, 0, 0);
}
(pPacket and IP is a pointer to a custom structure with some NDIS_BUFFERS and a LIST_ENTRY link)
( i am doing all this from within the ReceiveHandler function entry point)
any ideas??
Thanks !!
Firstly,
IP = (PPACKET) pEnt;
is going to give you garbage. pEnt is a pointer to LIST_ENTRY
struct. In the fluke case where the LIST_ENTRY in your PACKET struct
just happens to be the first element then
IP = (PPACKET) pEnt->fLink;
might work. However, you need to check out the CONTAINING_RECORD
macro and scan the WDK samples for an example of its use.
Mark.
At 11:53 24/01/2011, xxxxx@hotmail.com wrote:
Hi,
I am de-allocating memory for a structure(and its buffers) that
where allocated beforehand but crash happens when i am doing trying
to do this.
After some testing i noticed that when i deallocate the structers
by getting the pointer to the structures from an entry list its
crashing but when i use the pointer that they where created with it
works fine.
here is the code:
//Allocation
NdisAllocateMemoryWithTag(&pPacket, sizeof(PACKET),‘oiuN’)
NdisAllocateMemoryWithTag(&pPacket->aStructA,LookaheadBufferSize, ‘oiuN’);
NdisAllocateMemoryWithTag(&pPacket->aStructA,HeaderBufferSize, ‘oiuN’);
//De-allocation code
pEnt = RemoveHeadList(&masterstruct->Packets);
IP = (PPACKET) pEnt;
if(IP!=NULL)
{
NdisFreeMemory(IP->aStructA,0,0);
NdisFreeMemory(IP->aStructB,0,0);
NdisFreeMemory(IP, 0, 0);
}
(pPacket and IP is a pointer to a custom structure with some
NDIS_BUFFERS and a LIST_ENTRY link)
( i am doing all this from within the ReceiveHandler function entry point)
any ideas??
Thanks !!
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
Thx the problem was when i was casting as you said.
when i used he macro it worked.
what is i cant understand is that when i read the data it semed valid (i.E it was casting good since i read the data and it was valid so the ptr returned must be have been good)
First, RemoveHeadList NEVER returns NULL. Before you call it, you need to check if the list is not empty: IsListEmpty()
xxxxx@hotmail.com wrote:
Hi,
I am de-allocating memory for a structure(and its buffers) that where allocated beforehand but crash happens when i am doing trying to do this.
After some testing i noticed that when i deallocate the structers by getting the pointer to the structures from an entry list its crashing but when i use the pointer that they where created with it works fine.
here is the code:
//Allocation
NdisAllocateMemoryWithTag(&pPacket, sizeof(PACKET),‘oiuN’)
NdisAllocateMemoryWithTag(&pPacket->aStructA,LookaheadBufferSize, ‘oiuN’);
NdisAllocateMemoryWithTag(&pPacket->aStructA,HeaderBufferSize, ‘oiuN’);
You can see there’s a typo there, right? If you cut-and-pasted that
from the actual code, you need to change the third one to aStructB, not
aStructA. If you retyped this character by character, then who knows.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.