Avoid Memory Corruption when Assigning a CComBSTR to a CComVariant's bstrVal Member

原创 2007年09月28日 17:25:00

Although the CComBSTR = operator is overloaded to make a copy of the string, this is not the case when assigning a CComVariant's bstrVal member to a CComBSTR. In this case, you need to make an explicit copy:

CComVariant bstrTarget;
CComBSTR strSource("test");

// Use CComBSTR::Copy to make a copy
// of the source string.
bstrTarget.bstrVal = strSource.Copy();
If you don't make a copy of the source string, it will wind up being freed twice—once by the CComVariant's destructor, and once by the original CComBSTR's destructor. 
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

How to Avoid ConcurrentModificationException when using an Iterator

Java Collection classes are fail-fast which means that if the Collection will be changed while some ...

Bind: Address Already in Use Or How to Avoid this Error when Closing TCP Connections

In order for a network connection to close, both ends have to send FIN (final) packets, which indi...

heap corruption detected: CRT detected that the application wrote to memory

错误的现象是这样的: 在程序的开始处我申请了一块内存,中间对其进行了一些操作,在程序结束处,释放内存的时候,引起错误: HEAP CORRUPTION DETECTED:after Nor...

Threads are going to be renewed over time to try and avoid a probable memory leak.

信息: Stopping service Catalina 八月 21, 2014 8:48:45 下午 org.apache.catalina.loader.WebappClassLoader cl...

ORACLE ORA-04030之 out of process memory when trying to allocate

近期巡检中,一oracle 11g rac节点出现ORACLE ORA-04030之 out of process memory when trying to allocate报错,查询ORACLE官...

【已解决】iOS程序出现警告:ARC Semantic Issue,Assigning retained object to unsafe property;object will be releas

【问题】 BirdWatching的iOS app,现在想要去多多折腾,搞懂不同property的setter修饰符:assign,copy,retain等的更深层的含义。 所以,专门去把代码改为...

内存写越界导致破环堆结构引起的崩溃问题定位经验[如报错malloc(): memory corruption或free(): invalid next size]

转载

Study Note: Shared Memory Optimisation -- avoid of bank conflict

This article is illustrated bases on 2.x computation device:  Typically speaking, a shared memory ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)