R
Rohan lotlikat
Hi Guys
I am facing a memory leak problem .. and i cant figure out whats causing it .
.. here is the code which leaks
Please help.. its making me crazy..
for(int j =1;j<=mailItemCount;j++)
{
/*CComPtr Member definition. */
if(bEndAllThreads)
_endthread();
pItems->Item((CComVariant)j,&pDisp);
{
CComQIPtr <Outlook::_MailItem> pMailItem(pDisp);
if(pMailItem == NULL )
continue;
/* get MAPIObject to query IMessage*/
pMailItem->get_MAPIOBJECT(&pUnk);
}
pUnk->QueryInterface(IID_IMessage,(void**)&Msg);
Msg->AddRef();
Msg->GetRecipientTable(0,&lpIMAPITable);
Msg->Release();
if(lpIMAPITable)
hres = lpIMAPITable->SetColumns((LPSPropTagArray)&abCol, 0);
else
return 0;
if(FAILED(hres))
return 0;
hres = lpIMAPITable->SeekRow(BOOKMARK_BEGINNING, 0, NULL);
if(FAILED(hres))
return 0;
hres = lpIMAPITable->GetRowCount(0,&ulCount);
LPSPropValue lpsProp;
ULONG uflags =0;
uflags = PR_SENDER_EMAIL_ADDRESS;
HrGetOneProp((IMAPIProp*)pUnk,uflags,(LPSPropValue FAR *)&lpsProp);
if(!(lpsProp))
continue;
bSenderEmail = lpsProp->Value.lpszA;
if (lpsProp)
MAPIFreeBuffer(lpsProp);
lpsProp = NULL;
uflags = PR_SENDER_NAME;
HrGetOneProp((IMAPIProp*)pUnk,uflags,(LPSPropValue FAR *)&lpsProp);
bSenderName = lpsProp->Value.lpszA;
pUnk->Release();
if (lpsProp)
MAPIFreeBuffer(lpsProp);
lpsProp = NULL;
CComBSTR bcontactList(bSenderEmail);
CComBSTR bnameList(bSenderName);
bcontactList += ";";
bnameList += ";";
ScanMsg = "";
ScanMsg += "Processing ";
ScanMsg += _itoa(j,buf,10);
ScanMsg += " of ";
ScanMsg += _itoa(mailItemCount,buf,10);
SetDlgItemText(IDC_STATSCANMSG,OLE2CT(ScanMsg));
StepProgressBar();
if(bSenderEmail.Length() <= 0)
{
// pMailItem.Release();
continue ;
}
LPSRestriction lpSRes = NULL;
SPropValue lpSprop;
lpSprop.ulPropTag = PR_EMAIL_ADDRESS;
MAPIAllocateBuffer(sizeof(SRestriction),(LPVOID*)&lpSRes);
lpSRes->rt = RES_CONTENT ;
lpSRes->res.resContent.ulFuzzyLevel = FL_FULLSTRING ;
lpSRes->res.resContent.ulPropTag = PR_EMAIL_ADDRESS;
for(i = m_UserEmailList.begin();i != m_UserEmailList.end();i++)
{
if(blScanMail)
break;
lpSprop.Value.lpszA = (char*)(*i).c_str();
lpSRes->res.resContent.lpProp = &lpSprop;
hres = lpIMAPITable->FindRow(lpSRes,BOOKMARK_BEGINNING,0);
MAPIFreeBuffer(lpSRes->res.resContent.lpProp);
if((_stricmp(OLE2T(bSenderEmail),(*i).c_str()) == 0) ||(hres == S_OK ))
{
blScanMail = true;
break;
}
}
MAPIFreeBuffer(lpSRes);
if(!blScanMail)
{
if(pDisp!= NULL)
pDisp->Release();
continue;
}
/* Define row set */
LPSRowSet pABCRows = NULL;
CheckInContact(OLE2T(bSenderEmail),OLE2T(bSenderName));
for(int iloop=0;iloop<(int)ulCount;iloop++)
{
hres = lpIMAPITable->QueryRows(1,NULL,&pABCRows);
if(FAILED(hres))
return 0;
if(pABCRows->cRows > 0)
if((pABCRows->aRow[0].lpProps[abPR_RECIPIENT_TYPE].Value.l == 1) ||
(pABCRows->aRow[0].lpProps[abPR_RECIPIENT_TYPE].Value.l == 2))
{
hres = pABCRows->aRow[0].lpProps[abPR_DISPLAY_NAME].Value.err;
if(SUCCEEDED(hres))
CheckInContact(pABCRows->aRow[0].lpProps[abPR_EMAIL_ADDRESS].Value.
lpszA,
pABCRows->aRow[0].lpProps[abPR_DISPLAY_NAME].Value.lpszA);
}
for (int irow = 0; irow < pABCRows->cRows; ++irow)
MAPIFreeBuffer(pABCRows->aRow[irow].lpProps);
MAPIFreeBuffer(pABCRows);
}
lpIMAPITable->Release();
blScanMail = false;
if(pDisp!= NULL){
pDisp->Release();
pDisp=NULL;
}
}
I am facing a memory leak problem .. and i cant figure out whats causing it .
.. here is the code which leaks
Please help.. its making me crazy..
for(int j =1;j<=mailItemCount;j++)
{
/*CComPtr Member definition. */
if(bEndAllThreads)
_endthread();
pItems->Item((CComVariant)j,&pDisp);
{
CComQIPtr <Outlook::_MailItem> pMailItem(pDisp);
if(pMailItem == NULL )
continue;
/* get MAPIObject to query IMessage*/
pMailItem->get_MAPIOBJECT(&pUnk);
}
pUnk->QueryInterface(IID_IMessage,(void**)&Msg);
Msg->AddRef();
Msg->GetRecipientTable(0,&lpIMAPITable);
Msg->Release();
if(lpIMAPITable)
hres = lpIMAPITable->SetColumns((LPSPropTagArray)&abCol, 0);
else
return 0;
if(FAILED(hres))
return 0;
hres = lpIMAPITable->SeekRow(BOOKMARK_BEGINNING, 0, NULL);
if(FAILED(hres))
return 0;
hres = lpIMAPITable->GetRowCount(0,&ulCount);
LPSPropValue lpsProp;
ULONG uflags =0;
uflags = PR_SENDER_EMAIL_ADDRESS;
HrGetOneProp((IMAPIProp*)pUnk,uflags,(LPSPropValue FAR *)&lpsProp);
if(!(lpsProp))
continue;
bSenderEmail = lpsProp->Value.lpszA;
if (lpsProp)
MAPIFreeBuffer(lpsProp);
lpsProp = NULL;
uflags = PR_SENDER_NAME;
HrGetOneProp((IMAPIProp*)pUnk,uflags,(LPSPropValue FAR *)&lpsProp);
bSenderName = lpsProp->Value.lpszA;
pUnk->Release();
if (lpsProp)
MAPIFreeBuffer(lpsProp);
lpsProp = NULL;
CComBSTR bcontactList(bSenderEmail);
CComBSTR bnameList(bSenderName);
bcontactList += ";";
bnameList += ";";
ScanMsg = "";
ScanMsg += "Processing ";
ScanMsg += _itoa(j,buf,10);
ScanMsg += " of ";
ScanMsg += _itoa(mailItemCount,buf,10);
SetDlgItemText(IDC_STATSCANMSG,OLE2CT(ScanMsg));
StepProgressBar();
if(bSenderEmail.Length() <= 0)
{
// pMailItem.Release();
continue ;
}
LPSRestriction lpSRes = NULL;
SPropValue lpSprop;
lpSprop.ulPropTag = PR_EMAIL_ADDRESS;
MAPIAllocateBuffer(sizeof(SRestriction),(LPVOID*)&lpSRes);
lpSRes->rt = RES_CONTENT ;
lpSRes->res.resContent.ulFuzzyLevel = FL_FULLSTRING ;
lpSRes->res.resContent.ulPropTag = PR_EMAIL_ADDRESS;
for(i = m_UserEmailList.begin();i != m_UserEmailList.end();i++)
{
if(blScanMail)
break;
lpSprop.Value.lpszA = (char*)(*i).c_str();
lpSRes->res.resContent.lpProp = &lpSprop;
hres = lpIMAPITable->FindRow(lpSRes,BOOKMARK_BEGINNING,0);
MAPIFreeBuffer(lpSRes->res.resContent.lpProp);
if((_stricmp(OLE2T(bSenderEmail),(*i).c_str()) == 0) ||(hres == S_OK ))
{
blScanMail = true;
break;
}
}
MAPIFreeBuffer(lpSRes);
if(!blScanMail)
{
if(pDisp!= NULL)
pDisp->Release();
continue;
}
/* Define row set */
LPSRowSet pABCRows = NULL;
CheckInContact(OLE2T(bSenderEmail),OLE2T(bSenderName));
for(int iloop=0;iloop<(int)ulCount;iloop++)
{
hres = lpIMAPITable->QueryRows(1,NULL,&pABCRows);
if(FAILED(hres))
return 0;
if(pABCRows->cRows > 0)
if((pABCRows->aRow[0].lpProps[abPR_RECIPIENT_TYPE].Value.l == 1) ||
(pABCRows->aRow[0].lpProps[abPR_RECIPIENT_TYPE].Value.l == 2))
{
hres = pABCRows->aRow[0].lpProps[abPR_DISPLAY_NAME].Value.err;
if(SUCCEEDED(hres))
CheckInContact(pABCRows->aRow[0].lpProps[abPR_EMAIL_ADDRESS].Value.
lpszA,
pABCRows->aRow[0].lpProps[abPR_DISPLAY_NAME].Value.lpszA);
}
for (int irow = 0; irow < pABCRows->cRows; ++irow)
MAPIFreeBuffer(pABCRows->aRow[irow].lpProps);
MAPIFreeBuffer(pABCRows);
}
lpIMAPITable->Release();
blScanMail = false;
if(pDisp!= NULL){
pDisp->Release();
pDisp=NULL;
}
}