As it's written in the MSDN documentation CComBSTR::operator= creates a copy of src. So when I write
someCComBSTR = std::to_wstring(someVal).c_str();
I will have a copy of the temporary and everything is ok. But I haven't found what happens with the previous value, will it be freed or rewritten, or I first should manually empty my CComBSTR object?
CComBSTRis defined in the header atlcomcli.h in Visual Studio's atlmfc/include directory. All assignment operators (operator=) release the currently owned data by callingSysFreeString(with some exceptions that aren't interesting here).The line of code posted in the question will not leak any resources. It is invoking the following assignment operator for
CComBSTR(comments added for clarity):