memory leak of API IOCreatePlugInInterfaceForService in IOKit

we are developing USB hid library to interact with HID device, however we're facing on memory lacking when we calling IOCreatePlugInInterfaceForService then calling IODestroyPlugInInterface, the memory is not released and each time of calling it take about 0.3 MB Ram, after long time running, the program crash because runout of memory. what should we do in this case to avoid memory leak?

// Create a device interface/HANDLE
static BOOL CreateHidDeviceInterface(io_object_t deviceObject, HANDLE* pHandle)
{
BOOL retVal = FALSE;
IOCFPlugInInterface** ppPluginInterface = NULL;
SInt32 score = 0;
IOReturn pluginResult;
HRESULT interfaceResult;
// Create a plugin so we can create an interface
pluginResult = IOCreatePlugInInterfaceForService(deviceObject, kIOHIDDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &ppPluginInterface, &score);
if (pluginResult == kIOReturnSuccess)
{
// Create the interface (HANDLE)
interfaceResult = (*ppPluginInterface)->QueryInterface(ppPluginInterface, CFUUIDGetUUIDBytes(kIOHIDDeviceInterfaceID), (void**)pHandle);
if (interfaceResult == S_OK)
{
retVal = TRUE;
}
        IODestroyPlugInInterface(ppPluginInterface);
}
return retVal;
}

are you sure you're leaking memory created by the call to IOCreatePlugInInterface? It creates an interface, as its name suggests, returned in pHandle. Are you releasing that interface when you're done with it?

memory leak of API IOCreatePlugInInterfaceForService in IOKit
 
 
Q