Help with memory leak
- From: Joseph <jose.4568@xxxxxxxxxxx>
- Date: Mon, 17 Mar 2008 12:03:47 +0100
Hi all,
I'm new to COM so this could be a silly question, but I have a memory leak somewhere, and I really can't find it, here's my code (I removed
some sanity checks just to make the listing shorter):
BOOL SetInterface(UINT myType){
// iAcc: is an IAccessible* and it's already initialized
// tiAcc: is an IAccessible*
long childCount, returnCount, i;
VARIANT varChild, *pArray = NULL;
if(tiAcc){
tiAcc->Release();
tiAcc = NULL;
}
if(iAcc->get_accChildCount(&childCount) != S_OK)
return FALSE;
pArray = new(std::nothrow) VARIANT[childCount];
if(FAILED(AccessibleChildren(iAcc, 0L, childCount,
pArray, &returnCount))){
delete[] pArray;
return FALSE;
}
for (i = 0; i < returnCount; i++){
VARIANT vtChild = pArray[i];
if(vtChild.vt != VT_DISPATCH)
continue;
if((vtChild.pdispVal)->QueryInterface(IID_IAccessible,
(void**)&tiAcc) != S_OK){
continue;
}
varChild.vt = VT_I4;
varChild.lVal = vtChild.lVal;
tiAcc->get_accRole(varChild, &trVariant);
if(trVariant.lVal == myType){
delete[] pArray;
return TRUE;
}
tiAcc->Release();
}
delete[] pArray;
tiAcc->Release();
return FALSE;
}
SetInterface() function leaks 4kb of memory each time I call it, this function is used to set the attribute tiAcc inside my class, and of course I call Release() on that interface each time I don't need it anymore (I even used something like while(tiAcc->Release()); in my
tests :)).
This other function leaks the same amount of memory, and of course I ALWAYS call SysFreeString() on bName after reading it.
BOOL GetName(BSTR *bName)
{
// tiAcc is an IAccessible* and it's already initialized
VARIANT vtChild;
vtChild.vt = VT_I4;
vtChild.lVal = CHILDID_SELF;
if(tiAcc->get_accName(vtChild, bName) != S_OK)
return FALSE;
return TRUE;
}
Would you please tell me what's wrong in this snippet? I even used the example published on MSDN after the description of AccessibleChildren() API and it leaks a lot too! :(.
Thanx a lot in advance for your help!!!!
J.
.
- Follow-Ups:
- Re: Help with memory leak
- From: Igor Tandetnik
- Re: Help with memory leak
- Prev by Date: Re: 0x80029C4A Error loading type library/DLL. Related to Outlook.Application.
- Next by Date: Re: Help with memory leak
- Previous by thread: "Access violation" when trying to operate the HTML DOM in my COM o
- Next by thread: Re: Help with memory leak
- Index(es):
Relevant Pages
|