March 6th, 2013

The Dam Has Burst! Run For Your Lives!

It appears that we have a big memory leak in our application. Some of it is my fault, because I copied incorrectly working code without bothering to check how a particular class worked.

Short form: our COM routines return a BSTR. If you assign that BSTR value to an object of the CComBSTR class, the value is copied to the internal storage for the class instead of being attached to the internal storage. So if you were counting on the BSTR being cleaned up when the CComBSTR object went out of scope, well, you were right for one out of two strings.


The solution is to call the Attach method for the CComBSTR class so that it takes ownership of the pointer.

And happily, I figured this out before code freeze.

Now we just need to fix all of the places that are doing it wrong.