locked
NDIS 6 LWF driver sending problem RRS feed

  • Question

  • Hi,

    I want to send the packets from an NDIS 6 LWF. Here the packets just include an Ethernet Header and some data. The following is the procedures:

    1. Call NdisAllocateNetBufferListPool to allocate a pool. In the FilterAttachHandler:

    2. In the SendNetBufferListsHandler and ReceiveNetBufferListsHandler call function for complete the original package.

    3. Allocate a MDL and NBL

    4. Copy the new data to the MDL using NdisMoveMemory()

    5. Call functions NdisFSendNetBufferLists or NdisFIndicateReceiveNetBufferLists for new NBL.

    6. In the SendNetBufferListsCompleteHandler and ReceiveNetBufferListsHandler free all allocated memory.

    Everything works fine, but I'm getting a memory leak. Why ? All the functions of the release is called, but the memory still leaked.

    A memory leak occurs when I call NdisFSendNetBufferLists.

    Thanks in advance.

    P.S. Sorry for my bad English ))

    P.S.S. I am writing here because not find forum on NDIS

     

     


    Monday, June 27, 2011 6:29 PM

All replies

  • There are only a few things that can be leaked, so check each of them one-by-one:

    1. The NBL Pool, allocated through NdisAllocateNetBufferListPool, must eventually be freed with NdisFreeNetBufferListPool.
    2. Every NET_BUFFER_LIST, allocated through NdisAllocateNetBufferAndNetBufferList must be freed with NdisFreeNetBufferList.
    3. Every MDL, allocated through NdisAllocateMdl must be freed with NdisFreeMdl.
    4. Any temporary allocations made through NdisAllocateMemory (or NdisAllocateMemoryWithTag or NdisAllocateMemoryWithTagPriority) must be freed with NdisFreeMemory.

    After reviewing the code, if you still aren't sure where the leak is, you can make a simple wrapper function around the allocation routines that just increments a counter.  Then make a wrapper that decrements the counter.  If the counter is non-zero when the filter is detached, then you know that you've leaked memory.  For example:

    PMDL
    myAllocateMdl(PMS_FILTER Filter, PVOID Address, ULONG Length)
    {
        PMDL Mdl = NdisAllocateMdl(Filter->NdisHandle, Address, Length);
        if (Mdl)
            InterlockedIncrement(Filter->MdlsAllocated);
        return Mdl;
    }

    When sending, use NET_BUFFER_LIST.SourceHandle to mark packets that you allocated.  When NET_BUFFER_LISTs are completed back to your filter (FilterSendNetBufferListsComplete) make sure that you are identifying the NET_BUFFER_LISTs that you allocated, and make sure that you are pulling those out of the list and freeing those.  Don't call NdisFSendNetBufferListsComplete on those (but still call NdisFSendNetBufferListsComplete for all other NET_BUFFER_LSITs).

     

    P.S., the best place for NDIS is here: http://social.msdn.microsoft.com/Forums/en-US/wdk/threads

    Monday, June 27, 2011 7:17 PM
  • Thank you for your reply.

    My full post is here (http://www.osronline.com/showthread.cfm?link=207625)

    I checked all the functions of releases caused. But the memory still leaked.

    Tuesday, June 28, 2011 7:07 AM