The [out] attribute in an IDL declaration is a serious interaction issue. This means that your COM server will allocate an array and the caller needs to free it. This is very rarely suitable for a good result, there is no guarantee that your server and your client will use the same heap. And it will always fail if you use the C runtime allocator using the malloc () or new [] function, CRT uses its own heap, which the caller can never get if they do not share the same version of CRT. The odds are very small, which is generally zero when you go through the CLR.
That's why it is bombing, the CLR knows that it needs to free the array after copying it to a managed array. It will use CoTaskMemFree (), using the heap reserved for communication distributions between COM. Of course, you did not use CoTaskMemAlloc () to allocate the array.
A common solution to this problem is to provide the caller with an array that the caller fills it with. This requires [in, out] for the parameter. And an additional parameter indicating the size of this passed array is [sizeis] to tell the marshaller about it. Very effective, no distribution required. Using the automation type SAFEARRAY allows you to not specify an additional argument, the CLR knows about this type.
source share