I have some code in C# which has a com wrapper. This com wrapper is used in a native c++ application. The c++ code uses a method which returns an array of instances of a class from the c# library. The instances come from a SafeArray like so:
for (long i =min; i<=max;i++)
{
IMyInterface *l = (IMyInterface *)malloc(sizeof IMyInterface );
SafeArrayGetElement(array,&i, &l);
<other code>
}
I want to free the memory allocated for the instance l, but if I call
free(l)
then I get a crash.
I have tried
VariantClear ((VARIANT*)l);
and using
SafeArrayDestroy(array)
but am still leaking 4 bytes for each instance in the array.
any ideas how I should go about freeing this memory?