See the question and my original answer on StackOverflow

There are many potential issues in your code, for example, all your methods GetBackDoorTextVariable(), GetValues(), GetBackDoorVariable(), GetValue() could build a bad variant.

However, one thing that doesn't seem ok whatsoever, is how you handle the CorrelationNames instance.

Because _variant_t is an automatic wrapper classes and handles memory releases for you, you're not supposed to play with it too deeply. But in your code, you free the memory that this variant holds (with a SafeArrayDestroy call), without setting the parray member to null. When the destructor runs, it tries to free a null pointer and crashes.

So, remove the SafeArrayDestroy(psa) line and it should work better, at least for this issue.