Doesn’t this code a leak if unkown does not conform to the interface?
The inherited c’tor has addRef default to true, so it would claim a reference for this->ptr which is not released because the ptr is directly set to 0?
template <class I>
inline FUnknownPtr<I>::FUnknownPtr (FUnknown* unknown)
{
if (unknown && unknown->queryInterface (I::iid, (void**)&this->ptr) != kResultOk)
this->ptr = 0;
}
I think this must be changed like this, matching its own assignment logic:
template <class I>
inline FUnknownPtr<I>::FUnknownPtr (FUnknown* unknown)
{
if (unknown && unknown->queryInterface (I::iid, (void**)&this->ptr) != kResultOk)
IPtr<I>::operator=(0);
}
Or am I missing something?
-Stefan