【问题标题】:Who should clean IPropertyBag2 GetPropertyInfo allocated string?Who should clean IPropertyBag2 GetPropertyInfo allocated string?
【发布时间】:2022-12-01 14:10:22
【问题描述】:

I am analyzing some piece of c++ COM code. I'm trying to find a leak and I found suspicious code in implementation of IPropertyBag2::GetPropertyInfo.

When pPropBag[i].pstrName member is filled some bytes are allocated.

pPropBag[i].pstrName = lstrcpyW(ATL::AtlCoTaskMemCAlloc(name.size() + 1, sizeof(WCHAR)), name.c_str());

I think this code is strange. And I can't find deallocation of bytes for name in this project. May it be cleared from caller of COM interface or automatically cleaned by COM?

I now that is better to use StringCchCopy instead of lstrcpyW

Thank you!

【问题讨论】:

  • See GetPropertyInfo method - Remarks -"When you implement this method, use CoTaskMemAlloc to allocate memory for the pstrName member of pPropBag." ..."When you call this method, use CoTaskMemFree to free the pstrName member of pPropBag"So this memory needs call site (client) clean-up).
  • o! Thank you, I missunderstood this remark

标签: c++ windows com


【解决方案1】:

See GetPropertyInfo method - Remarks - "When you implement this method, use CoTaskMemAlloc to allocate memory for the pstrName member of pPropBag." ... "When you call this method, use CoTaskMemFree to free the pstrName member of pPropBag" So this memory needs call site (client) clean-up). – Richard Critten 17 hours ago

【讨论】:

    猜你喜欢
    • 2022-12-27
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    • 2020-10-08
    • 2014-11-13
    • 1970-01-01
    • 1970-01-01
    • 2021-08-10
    相关资源
    最近更新 更多