Bug in FUnknownPtr<>?

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

No, the constructor of FUnknownPtr calls the default IPtr constructor, not the one with an FUnknown argument. The ptr is set to zero in the case of failure because the queryInterface function may have set the ptr to something.

Ok understood - so this is merely defensive code.
Thanks for the clarification!
-Stefan