Crash after MAPISESSION::ShowForm but only if I free resources

Crash after MAPISESSION::ShowForm but only if I free resources

Post by Angu » Thu, 09 Apr 2009 18:23:14


Hello

I am opening an Outlook Contacts folder contact like this:

hr=pSession->ShowForm(NULL, m_pMDB, pContactsFolder, NULL, MsgToken,
NULL, MAPI_NEW_MESSAGE, 0, 0, MAPI_ACCESS_READ, "IPM.Contact");

But after the user dismisses the dialog or saves if I free up like
this after the above ShowForm call:

FreeProws(pRows);
if (pProps) MAPIFreeBuffer(pProps);

if (pTable) pTable->Release();
if (pContactsFolder) pContactsFolder->Release();

if (pStoresTbl) pStoresTbl->Release();

if (m_pMDB) m_pMDB->Release();
// Logoff
if (pSession)
{
pSession->Logoff(0,0,0);
pSession->Release();
}
MAPIUninitialize();

I get an access violation - 0xC0000005: Access Violation

But if I return immediately after the ShowForm and don't release then
I get no crash. But presumably a memory leak! Or should I NOT
release after displaying the form?

What am I doing wrong?

Angus
 
 
 

Crash after MAPISESSION::ShowForm but only if I free resources

Post by Tom » Fri, 10 Apr 2009 00:01:24

Hi Angus,

Are you doing this from a different process or are you doing this as an
Outlook add-in?

Tom -

 
 
 

Crash after MAPISESSION::ShowForm but only if I free resources

Post by Angu » Fri, 10 Apr 2009 01:29:10


It is all called from a single process.

I realised that I was not releasing all resources and also not in
correct order.

This is what I do now (let me know if not correct):

pMsg->Release(); //MAPIFOLDER::OpenEntry
}

FreeProws(pRows); //HrQueryAllRows on MAPITABLE
if (pTable) pTable->Release(); //MAPIFOLDER::GetContentsTable
if (pContactsFolder) pContactsFolder->Release(); //MDB::OpenEntry
if (pProps) MAPIFreeBuffer(pProps); //HrGetOneProp
(PR_IPM_CONTACT_ENTRYID
if(m_pInboxFolder) m_pInboxFolder->Release(); //MDB::OpenEntry
if (m_pMDB) m_pMDB->Release(); //MAPISESSION::OpenMsgStore

FreeProws(pRow); //HrQueryAllRows for default msg store
if (pStoresTbl) pStoresTbl->Release(); //
MAPISESSION::GetMsgStoresTable

// Logoff
if (pSession)
{
pSession->Logoff(0,0,0);
pSession->Release();
}

MAPIUninitialize();

It no longer crashes. Does this look correct? I can provide complete
code if required.
 
 
 

Crash after MAPISESSION::ShowForm but only if I free resources

Post by Tom » Fri, 10 Apr 2009 01:40:07

It looks okay to me.

Yes MAPI is not forgiving if you release interfaces in the incorrect order
or forget to release an interface.








It is all called from a single process.

I realised that I was not releasing all resources and also not in
correct order.

This is what I do now (let me know if not correct):

pMsg->Release(); //MAPIFOLDER::OpenEntry
}

FreeProws(pRows); //HrQueryAllRows on MAPITABLE
if (pTable) pTable->Release(); //MAPIFOLDER::GetContentsTable
if (pContactsFolder) pContactsFolder->Release(); //MDB::OpenEntry
if (pProps) MAPIFreeBuffer(pProps); //HrGetOneProp
(PR_IPM_CONTACT_ENTRYID
if(m_pInboxFolder) m_pInboxFolder->Release(); //MDB::OpenEntry
if (m_pMDB) m_pMDB->Release(); //MAPISESSION::OpenMsgStore

FreeProws(pRow); //HrQueryAllRows for default msg store
if (pStoresTbl) pStoresTbl->Release(); //
MAPISESSION::GetMsgStoresTable

// Logoff
if (pSession)
{
pSession->Logoff(0,0,0);
pSession->Release();
}

MAPIUninitialize();

It no longer crashes. Does this look correct? I can provide complete
code if required.