Convert CComBSTR to _bstr_t with fcopy as false

I believe the following leads to a memory access violation error because a false parameter (fcopy) causes memory to be freed up for CComBSTR:

CComBSTR myCComBSTR;
string strMyCComBSTR = string(_bstr_t(myCComBSTR, false));

However, I'm not quite sure why this is so, since the MSDN documentation says fcopy:

If false, the bstr argument is attached to the new object without copying by phone to SysAllocString.

My question is:

  • Am I saying that this is a problem.
  • If so, why?

thank

+3
source share
1 answer

Yes, this is a problem - and myCComBSTR, and a temporary attempt will try to free the line, as they both will think that they own it.

, fcopy false " , , ". , myCComBSTR, , , - fcopy false. . myCComBSTR - double free, undefined.

+2

Source: https://habr.com/ru/post/1757980/


All Articles