- 1 year ago
Proper way of freeing buffers when using NdisSendPackets? (NDIS 5.0)
When using NDIS 5.0 and the NdisSendPackets
function to send packets, you should properly manage and free the associated buffers to prevent memory leaks. Here's a suggested approach for freeing the buffers:
Allocate packet buffers: Before calling
NdisSendPackets
, allocate packet buffers using theNdisAllocatePacket
function. You can allocate multiple packets if needed.Set packet data and length: Use the
NdisAllocatePacket
function to associate data buffers with each packet and set the buffer lengths accordingly.Call
NdisSendPackets
: Pass the allocated packets toNdisSendPackets
to send them.Complete the send operation: After the send operation completes, you will receive a call to your MiniportSendComplete function. In this function, you can free the packet buffers and any associated resources.
Here's an example implementation of the MiniportSendComplete
function:
CVOID MiniportSendComplete(
NDIS_HANDLE MiniportAdapterContext,
PNDIS_PACKET Packet,
NDIS_STATUS Status
)
{
// Process the send completion and free the associated resources
NdisFreePacket(Packet);
// Free any other resources associated with the packet if needed
}
In the MiniportSendComplete
function, you can use NdisFreePacket
to release the packet buffer associated with the Packet
parameter. If you have any additional resources associated with the packet, ensure they are freed as well.
It's important to note that the above approach assumes that the packet buffers were allocated using NdisAllocatePacket
and the associated resources are managed properly. The specifics of buffer allocation and freeing may vary depending on your code implementation and requirements.
Make sure to carefully review the NDIS documentation and guidelines for proper usage and handling of buffers in your specific NDIS version and environment.