Freeing WinSNMP Descriptors
The WinSNMP programming environment assigns the deallocation of descriptor resources to the WinSNMP implementation or the WinSNMP application, depending on which component allocates the memory for the descriptor.
To free the resources for an smiOID or an smiOCTETS descriptor, the following rules apply:
For input parameters
Because the WinSNMP application allocates the memory for input objects with variable lengths, the application must free that memory using an appropriate function. For example, if the application allocated the resources with a call to the GlobalAlloc function, it should use the GlobalFree function to deallocate the resources. If the application allocated the resources with a call to the HeapAlloc function, it should call the HeapFree function.
For output parameters
A call to any of the following functions results in the implementation allocating memory for an smiOID or an smiOCTETS descriptor: SnmpGetVb, SnmpEncodeMsg, SnmpOidCopy, SnmpContextToStr, and SnmpStrToOid.
Because the implementation allocates the memory for these output objects, the application must call the SnmpFreeDescriptor function to deallocate the resources. This function enables the implementation to free the memory allocated for the ptr member of these structures.
To free the resources for an smiVALUE structure, a WinSNMP application must check the syntax member of an smiVALUE structure to correctly evaluate the value member of the structure. If the syntax member indicates that the value member is an smiOCTETS or an smiOID descriptor, and the implementation allocated the resources for the descriptor, the application must call SnmpFreeDescriptor. This enables the implementation to free the memory. If the application allocated the resources, it must free the memory using an appropriate function, as indicated earlier.
For more information, see Allocating WinSNMP Memory Objects.