Help with memory leak

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.
.



Relevant Pages

  • Re: MDAC memory leak
    ... when the storage should be freed. ...  Most libraries place the decision of when to free ... strcore leaks are hard to diagnose, because they mean you have an unfreed CString. ... There's a capability of breaking on a particular memory allocation, ...
    (microsoft.public.vc.mfc)
  • Re: MDAC memory leak
    ... when the storage should be freed. ...  Most libraries place the decision of when to free ... strcore leaks are hard to diagnose, because they mean you have an unfreed CString. ... There's a capability of breaking on a particular memory allocation, ...
    (microsoft.public.vc.mfc)
  • Re: tip50 Accepted
    ... This is also the version to be bundled with Tcl core 8.6 beta. ... Is it really true that memory leaks are being plugged in code which is ... It is really unbelievable that a developer would be hunting down ...
    (comp.lang.tcl)
  • Re: tip50 Accepted
    ... This is also the version to be bundled with Tcl core 8.6 beta. ... Is it really true that memory leaks are being plugged in code which is ...
    (comp.lang.tcl)
  • Re: FastMM 4.40 released (replacement memory manager for Delphi IDE and applications, free and open
    ... >> A fast replacement memory manager for Borland Delphi Win32 applications ... >> - Optionally reports memory leaks on program shutdown. ... >> the need for stack frames. ... If exception handling is not in place FastMM ...
    (borland.public.delphi.thirdpartytools.general)