// -------------------------------------------------------------------------------- // Olealloc.cpp // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved // Steven J. Bailey // -------------------------------------------------------------------------------- #include "pch.hxx" #include "dllmain.h" #include "olealloc.h" #include "smime.h" // -------------------------------------------------------------------------------- // CMimeAllocator::CMimeAllocator // -------------------------------------------------------------------------------- CMimeAllocator::CMimeAllocator(void) { if (NULL != g_pMoleAlloc) DllAddRef(); m_cRef = 1; } // -------------------------------------------------------------------------------- // CMimeAllocator::~CMimeAllocator // -------------------------------------------------------------------------------- CMimeAllocator::~CMimeAllocator(void) { if (this != g_pMoleAlloc) DllRelease(); } // -------------------------------------------------------------------------------- // CMimeAllocator::QueryInterface // -------------------------------------------------------------------------------- STDMETHODIMP CMimeAllocator::QueryInterface(REFIID riid, LPVOID *ppv) { // check params if (ppv == NULL) return TrapError(E_INVALIDARG); // Find IID if (IID_IUnknown == riid) *ppv = (IUnknown *)(IMimeAllocator *)this; else if (IID_IMimeAllocator == riid) *ppv = (IMimeAllocator *)this; else { *ppv = NULL; return TrapError(E_NOINTERFACE); } // AddRef It ((IUnknown *)*ppv)->AddRef(); // Done return S_OK; } // -------------------------------------------------------------------------------- // CMimeAllocator::AddRef // -------------------------------------------------------------------------------- STDMETHODIMP_(ULONG) CMimeAllocator::AddRef(void) { return (ULONG)InterlockedIncrement(&m_cRef); } // -------------------------------------------------------------------------------- // CMimeAllocator::Release // -------------------------------------------------------------------------------- STDMETHODIMP_(ULONG) CMimeAllocator::Release(void) { LONG cRef = InterlockedDecrement(&m_cRef); if (0 == cRef) delete this; return (ULONG)cRef; } // -------------------------------------------------------------------------------- // CMimeAllocator::Alloc // -------------------------------------------------------------------------------- STDMETHODIMP_(LPVOID) CMimeAllocator::Alloc(SIZE_T cb) { // Locals LPVOID pv; // Do I have a global Allocator Assert(g_pMalloc); // Allocate it pv = g_pMalloc->Alloc(cb); if (NULL == pv) { TrapError(E_OUTOFMEMORY); return NULL; } // Done return pv; } // -------------------------------------------------------------------------------- // CMimeAllocator::Realloc // -------------------------------------------------------------------------------- STDMETHODIMP_(LPVOID) CMimeAllocator::Realloc(void *pv, SIZE_T cb) { // Locals LPVOID pvNew; // Do I have a global Allocator Assert(g_pMalloc); // Realloc pvNew = g_pMalloc->Realloc(pv, cb); if (NULL == pvNew) { TrapError(E_OUTOFMEMORY); return NULL; } // Done return pvNew; } // -------------------------------------------------------------------------------- // CMimeAllocator::Free // -------------------------------------------------------------------------------- STDMETHODIMP_(void) CMimeAllocator::Free(void * pv) { // Better have pv Assert(pv && g_pMalloc); // If Not NULL if (pv) { // Free It g_pMalloc->Free(pv); } } // -------------------------------------------------------------------------------- // CMimeAllocator::GetSize // -------------------------------------------------------------------------------- STDMETHODIMP_(SIZE_T) CMimeAllocator::GetSize(void *pv) { return g_pMalloc->GetSize(pv); } // -------------------------------------------------------------------------------- // CMimeAllocator::DidAlloc // -------------------------------------------------------------------------------- STDMETHODIMP_(int) CMimeAllocator::DidAlloc(void *pv) { return g_pMalloc->DidAlloc(pv); } // -------------------------------------------------------------------------------- // CMimeAllocator::HeapMinimize // -------------------------------------------------------------------------------- STDMETHODIMP_(void) CMimeAllocator::HeapMinimize(void) { g_pMalloc->HeapMinimize(); } // -------------------------------------------------------------------------------- // CMimeAllocator::FreeParamInfoArray // -------------------------------------------------------------------------------- STDMETHODIMP CMimeAllocator::FreeParamInfoArray(ULONG cParams, LPMIMEPARAMINFO prgParam, boolean fFreeArray) { // Nothing to Free if (0 == cParams || NULL == prgParam) return S_OK; // Loop for (ULONG i=0; idwProps, IAP_FRIENDLY) && pAddress->pszFriendly) g_pMalloc->Free(pAddress->pszFriendly); // IAP_FRIENDLYW if (ISFLAGSET(pAddress->dwProps, IAP_FRIENDLYW) && pAddress->pszFriendlyW) g_pMalloc->Free(pAddress->pszFriendlyW); // IAP_EMAIL if (ISFLAGSET(pAddress->dwProps, IAP_EMAIL) && pAddress->pszEmail) g_pMalloc->Free(pAddress->pszEmail); // IAP_SIGNING_PRINT if (ISFLAGSET(pAddress->dwProps, IAP_SIGNING_PRINT) && pAddress->tbSigning.pBlobData) g_pMalloc->Free(pAddress->tbSigning.pBlobData); // IAP_ENCRYPTION_PRINT if (ISFLAGSET(pAddress->dwProps, IAP_ENCRYPTION_PRINT) && pAddress->tbEncryption.pBlobData) g_pMalloc->Free(pAddress->tbEncryption.pBlobData); // No legal props ZeroMemory(pAddress, sizeof(ADDRESSPROPS)); // Done return S_OK; } // -------------------------------------------------------------------------------- // CMimeAllocator::FreeAddressList // -------------------------------------------------------------------------------- STDMETHODIMP CMimeAllocator::FreeAddressList(LPADDRESSLIST pList) { // Invalid Arg if (NULL == pList || (pList->cAdrs > 0 && NULL == pList->prgAdr)) return TrapError(E_INVALIDARG); // Free Each Item for (ULONG i=0; icAdrs; i++) FreeAddressProps(&pList->prgAdr[i]); // Free the list SafeMemFree(pList->prgAdr); // Zero It ZeroMemory(pList, sizeof(ADDRESSLIST)); // Done return S_OK; } // -------------------------------------------------------------------------------- // CMimeAllocator::PropVariantClear // -------------------------------------------------------------------------------- STDMETHODIMP CMimeAllocator::PropVariantClear(LPPROPVARIANT pProp) { return MimeOleVariantFree(pProp); } // --------------------------------------------------------------------------- // CMimeAllocator::FreeThumbprint // --------------------------------------------------------------------------- STDMETHODIMP CMimeAllocator::FreeThumbprint(THUMBBLOB *pthumbprint) { if (pthumbprint->pBlobData) { Assert(0 != g_pMalloc->DidAlloc(pthumbprint->pBlobData)); MemFree(pthumbprint->pBlobData); } return S_OK; }