Parameters marshalled by stateless marshallers are being freed in too many scenarios. They should only be freed in unmanaged to managed ref scenarios (on the pointer that was passed in, not the value that is returned at the end of the method. In and Out parameters should not be cleaned up. Stateful marshallers can have free called on them as they can know which MarshalMode they are in and decide to actually free the underlying memory or not.