variant memory leak
I have a COM object with the interface IMyInterface and a function
GetDataList(), as below. But, when I go to use the GetDataList()
function, as in SomeFunction(), I have a memory leak.
Can anybody point out to me where my problem is?
Also, if there's an obviously more efficient way to implement the
GetDataList() function, please feel free to point it out to me.
Thank you,
PaulH
STDMETHODIMP CMyInterface::GetDataList(VARIANT * list)
{
//Init
VariantInit(list);
VariantClear(list);
//create safearray
CComSafeArray<BYTE> data;
CComSafeArrayBound bound[1];
bound[0].SetCount(dwSize);
bound[0].SetLowerBound(0);
hr = data.Create(bound, 1);
if (FAILED(hr))
return hr;
for (UINT i = 0; i < dwSize; ++i)
{
data.SetAt(i, m_DataBuffer[i]);
}
//copy safearray to return value
CComVariant vtReturnVal(data.Detach());
return vtReturnVal.Detach(list);
}
CComPtr<IMyInterface> m_spObject;
void SomeFunction()
{
_variant_t theList;
if (SUCCEEDED(m_spObject->GetDataList(&theList.GetVariant())))
{
//...
}
//...
}