Fix issue #376, patch from Milan Crha:
authorJulien Kerihuel <j.kerihuel@openchange.org>
Mon, 27 Feb 2012 14:46:02 +0000 (14:46 +0000)
committerJulien Kerihuel <j.kerihuel@openchange.org>
Mon, 27 Feb 2012 14:46:02 +0000 (14:46 +0000)
Decrease usage of NULL talloc contexts to minimum

25 files changed:
libexchange2ical/exchange2ical.c
libexchange2ical/ical2exchange.c
libmapi/FXICS.c
libmapi/IABContainer.c
libmapi/IMAPIContainer.c
libmapi/IMAPIFolder.c
libmapi/IMAPIProp.c
libmapi/IMAPISession.c
libmapi/IMAPISupport.c
libmapi/IMAPITable.c
libmapi/IMSProvider.c
libmapi/IMessage.c
libmapi/IMsgStore.c
libmapi/IProfAdmin.c
libmapi/IStoreFolder.c
libmapi/IStream.c
libmapi/IUnknown.c
libmapi/IXPLogon.c
libmapi/cdo_mapi.c
libmapi/emsmdb.c
libmapi/notif.c
libmapi/nspi.c
libmapi/property.c
libmapi/simple_mapi.c
utils/mapiprofile.c

index 2aa417d86a0887fbddf48e6198219747517d0a26..a014ac0262bcf8ddb1b1a896e98f13285eeec87c 100644 (file)
@@ -606,7 +606,7 @@ icalcomponent * _Exchange2Ical(mapi_object_t *obj_folder, struct exchange2ical_c
        uint32_t                        count;
        int                             i;
 
-       mem_ctx = talloc_named(NULL, 0, "exchange2ical");
+       mem_ctx = talloc_named(mapi_object_get_session(obj_folder), 0, "exchange2ical");
        exchange2ical_init(mem_ctx, &exchange2ical);
        
        /* Open the contents table */
index 2f6d1407a2ef823b4c6197764cb8b787133be86b..eb825c11a1fae71890dcf27c3464bbb4322d90c7 100644 (file)
@@ -350,7 +350,7 @@ void _IcalEvent2Exchange(mapi_object_t *obj_folder, icalcomponent *vevent)
        /*sanity check*/
        if(icalcomponent_isa(vevent) != ICAL_VEVENT_COMPONENT) return;
        
-       mem_ctx = talloc_named(NULL, 0, "ical2exchange");
+       mem_ctx = talloc_named(mapi_object_get_session(obj_folder), 0, "ical2exchange");
        ical2exchange.lpProps = talloc_array(mem_ctx, struct SPropValue, 2);
 
        ical2exchange_init(&ical2exchange, mem_ctx);
index 61f880c9f05dabb196b7fb4f8e7a22f1b1c562c7..b8f44fb46226d70622c9c004779332ccdecddc3b 100644 (file)
@@ -76,7 +76,7 @@ _PUBLIC_ enum MAPISTATUS GetLocalReplicaIds(mapi_object_t *obj_store,
        if ((retval = mapi_object_get_logon_id(obj_store, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetLocalReplicaIds");
+       mem_ctx = talloc_named(session, 0, "GetLocalReplicaIds");
        size = 0;
 
        /* Fill the GetLocalReplicaIds operation */
@@ -166,7 +166,7 @@ _PUBLIC_ enum MAPISTATUS FXDestConfigure(mapi_object_t *obj,
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "FXDestConfigure");
+       mem_ctx = talloc_named(session, 0, "FXDestConfigure");
        size = 0;
 
        /* Fill the ConfigureDestination operation */
@@ -252,7 +252,7 @@ _PUBLIC_ enum MAPISTATUS TellVersion(mapi_object_t *obj_store, uint16_t version[
        if ((retval = mapi_object_get_logon_id(obj_store, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "TellVersion");
+       mem_ctx = talloc_named(session, 0, "TellVersion");
        size = 0;
 
        /* Fill the operation */
@@ -344,7 +344,7 @@ _PUBLIC_ enum MAPISTATUS FXCopyFolder(mapi_object_t *obj, uint8_t copyFlags, uin
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "FXCopyFolder");
+       mem_ctx = talloc_named(session, 0, "FXCopyFolder");
        size = 0;
 
        /* Fill the CopyFolder operation */
@@ -455,7 +455,7 @@ _PUBLIC_ enum MAPISTATUS FXCopyMessages(mapi_object_t *obj, mapi_id_array_t *mes
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "FXCopyMessages");
+       mem_ctx = talloc_named(session, 0, "FXCopyMessages");
        size = 0;
 
        /* Fill the CopyMessages operation */
@@ -566,7 +566,7 @@ _PUBLIC_ enum MAPISTATUS FXCopyTo(mapi_object_t *obj, uint8_t level, uint32_t co
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "FXCopyTo");
+       mem_ctx = talloc_named(session, 0, "FXCopyTo");
        size = 0;
 
        /* Fill the CopyTo operation */
@@ -676,7 +676,7 @@ _PUBLIC_ enum MAPISTATUS FXCopyProperties(mapi_object_t *obj, uint8_t level, uin
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "FXCopyProperties");
+       mem_ctx = talloc_named(session, 0, "FXCopyProperties");
        size = 0;
 
        /* Fill the CopyProperties operation */
@@ -775,7 +775,7 @@ _PUBLIC_ enum MAPISTATUS FXGetBuffer(mapi_object_t *obj_source_context, uint16_t
        if ((retval = mapi_object_get_logon_id(obj_source_context, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "FXGetBuffer");
+       mem_ctx = talloc_named(session, 0, "FXGetBuffer");
        size = 0;
 
        /* Fill the GetBuffer operation */
@@ -873,7 +873,7 @@ _PUBLIC_ enum MAPISTATUS FXPutBuffer(mapi_object_t *obj_dest_context, DATA_BLOB
        if ((retval = mapi_object_get_logon_id(obj_dest_context, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "FXPutBuffer");
+       mem_ctx = talloc_named(session, 0, "FXPutBuffer");
        size = 0;
 
        /* Fill the PutBuffer operation */
@@ -1003,7 +1003,7 @@ _PUBLIC_ enum MAPISTATUS ICSSyncConfigure(mapi_object_t *obj, enum Synchronizati
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "RopSynchronizationConfigure");
+       mem_ctx = talloc_named(session, 0, "RopSynchronizationConfigure");
        size = 0;
 
        /* Fill the SyncConfigure operation */
@@ -1110,7 +1110,7 @@ _PUBLIC_ enum MAPISTATUS ICSSyncUploadStateBegin(mapi_object_t *obj_sync_context
        if ((retval = mapi_object_get_logon_id(obj_sync_context, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "ICSSyncUploadStateBegin");
+       mem_ctx = talloc_named(session, 0, "ICSSyncUploadStateBegin");
        size = 0;
 
        /* Fill the RopSynchronizationUploadStateBegin operation */
@@ -1188,7 +1188,7 @@ _PUBLIC_ enum MAPISTATUS ICSSyncUploadStateContinue(mapi_object_t *obj_sync_cont
        if ((retval = mapi_object_get_logon_id(obj_sync_context, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "ICSSyncUploadStateContinue");
+       mem_ctx = talloc_named(session, 0, "ICSSyncUploadStateContinue");
        size = 0;
 
        /* Fill the RopSynchronizationUploadStateBegin operation */
@@ -1264,7 +1264,7 @@ _PUBLIC_ enum MAPISTATUS ICSSyncUploadStateEnd(mapi_object_t *obj_sync_context)
        if ((retval = mapi_object_get_logon_id(obj_sync_context, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "ICSSyncUploadStateEnd");
+       mem_ctx = talloc_named(session, 0, "ICSSyncUploadStateEnd");
        size = 0;
 
        /* Fill the MAPI_REQ structure */
@@ -1344,7 +1344,7 @@ _PUBLIC_ enum MAPISTATUS SetLocalReplicaMidsetDeleted(mapi_object_t *obj_folder,
                return retval;
        }
 
-       mem_ctx = talloc_named(NULL, 0, __FUNCTION__);
+       mem_ctx = talloc_named(session, 0, __FUNCTION__);
        size = 0;
 
        /* Fill the SetLocalReplicaMidsetDeleted operation */
@@ -1446,7 +1446,7 @@ _PUBLIC_ enum MAPISTATUS ICSSyncOpenCollector(mapi_object_t *folder,
        if ((retval = mapi_object_get_logon_id(folder, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, __FUNCTION__);
+       mem_ctx = talloc_named(session, 0, __FUNCTION__);
        size = 0;
 
        /* Fill the SyncOpenCollector operation */
@@ -1533,7 +1533,7 @@ _PUBLIC_ enum MAPISTATUS ICSSyncGetTransferState(mapi_object_t *obj, mapi_object
                return retval;
        }
 
-       mem_ctx = talloc_named(NULL, 0, __FUNCTION__);
+       mem_ctx = talloc_named(session, 0, __FUNCTION__);
 
        /* Fill the SyncGetTransferState operation */
        request.handle_idx = 0x01;
index 404c8d04e2f5a4345ae58c1ded4c93d5cd7bc4f0..7505706af329f768bd95788e9d383276c7752a83 100644 (file)
@@ -81,7 +81,7 @@ _PUBLIC_ enum MAPISTATUS ResolveNames(struct mapi_session *session,
        OPENCHANGE_RETVAL_IF(!rowset, MAPI_E_INVALID_PARAMETER, NULL);
 
        nspi = (struct nspi_context *)session->nspi->ctx;
-       mem_ctx = talloc_named(NULL, 0, "ResolveNames");
+       mem_ctx = talloc_named(session, 0, "ResolveNames");
 
        switch (flags) {
        case MAPI_UNICODE:
@@ -166,7 +166,7 @@ _PUBLIC_ enum MAPISTATUS GetGALTable(struct mapi_session *session,
        OPENCHANGE_RETVAL_IF(!SRowSet, MAPI_E_INVALID_PARAMETER, NULL);
        OPENCHANGE_RETVAL_IF(!SPropTagArray, MAPI_E_INVALID_PARAMETER, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "GetGALTable");
+       mem_ctx = talloc_named(session, 0, "GetGALTable");
        nspi = (struct nspi_context *)session->nspi->ctx;
 
        if (ulFlags == TABLE_START) {
@@ -224,7 +224,7 @@ _PUBLIC_ enum MAPISTATUS GetGALTableCount(struct mapi_session *session,
        OPENCHANGE_RETVAL_IF(!session->nspi, MAPI_E_SESSION_LIMIT, NULL);
        OPENCHANGE_RETVAL_IF(!session->nspi->ctx, MAPI_E_SESSION_LIMIT, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "GetGALTableCount");
+       mem_ctx = talloc_named(session, 0, "GetGALTableCount");
        nspi = (struct nspi_context *) session->nspi->ctx;
 
        nspi->pStat->CurrentRec = 0;
@@ -295,7 +295,7 @@ _PUBLIC_ enum MAPISTATUS GetABRecipientInfo(struct mapi_session *session,
        OPENCHANGE_RETVAL_IF(!ppRowSet, MAPI_E_INVALID_PARAMETER, NULL);
        OPENCHANGE_RETVAL_IF(!username, MAPI_E_INVALID_PARAMETER, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "GetABRecipientInfo");
+       mem_ctx = talloc_named(session, 0, "GetABRecipientInfo");
        nspi_ctx = (struct nspi_context *)session->nspi->ctx;
 
        /* Step 1. Resolve the username */
index 8a5a21d5dc80e42047a0628c0b6881695861154d..4da03cd9cc331db48de3a5a15aee50dd5b7991d3 100644 (file)
@@ -100,7 +100,7 @@ _PUBLIC_ enum MAPISTATUS GetContentsTable(mapi_object_t *obj_container, mapi_obj
        if ((retval = mapi_object_get_logon_id(obj_container, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetContentsTable");
+       mem_ctx = talloc_named(session, 0, "GetContentsTable");
        size = 0;
 
        /* Fill the GetContentsTable operation */
@@ -226,7 +226,7 @@ _PUBLIC_ enum MAPISTATUS GetHierarchyTable(mapi_object_t *obj_container, mapi_ob
        if ((retval = mapi_object_get_logon_id(obj_container, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetHierarchyTable");
+       mem_ctx = talloc_named(session, 0, "GetHierarchyTable");
        size = 0;
 
        /* Fill the GetHierarchyTable operation */
@@ -326,7 +326,7 @@ _PUBLIC_ enum MAPISTATUS GetPermissionsTable(mapi_object_t *obj_container, uint8
        if ((retval = mapi_object_get_logon_id(obj_container, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetPermissionsTable");
+       mem_ctx = talloc_named(session, 0, "GetPermissionsTable");
        size = 0;
 
        /* Fill the GetPermissionsTable operation */
@@ -421,7 +421,7 @@ _PUBLIC_ enum MAPISTATUS GetRulesTable(mapi_object_t *obj_folder,
        if ((retval = mapi_object_get_logon_id(obj_folder, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetRulesTable");
+       mem_ctx = talloc_named(session, 0, "GetRulesTable");
        size = 0;
 
        /* Fill the GetRulesTable operation */
@@ -527,7 +527,7 @@ _PUBLIC_ enum MAPISTATUS ModifyPermissions(mapi_object_t *obj_table, uint8_t fla
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "ModifyPermissions");
+       mem_ctx = talloc_named(session, 0, "ModifyPermissions");
 
        /* Fill the ModifyPermissions operation */
        request.rowList = *permsdata;
@@ -644,7 +644,7 @@ _PUBLIC_ enum MAPISTATUS SetSearchCriteria(mapi_object_t *obj_container,
        if ((retval = mapi_object_get_logon_id(obj_container, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SetSearchCriteria");
+       mem_ctx = talloc_named(session, 0, "SetSearchCriteria");
        size = 0;
 
        /* Fill the SetSearchCriteria operation */
@@ -750,7 +750,7 @@ _PUBLIC_ enum MAPISTATUS GetSearchCriteria(mapi_object_t *obj_container,
        if ((retval = mapi_object_get_logon_id(obj_container, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetSearchCriteria");
+       mem_ctx = talloc_named(session, 0, "GetSearchCriteria");
        size = 0;
 
        /* Fill the GetSearchCriteria operation */
index 429a56d4073b306dca09c7240a077d1aa808a2d0..3e2dbfbc1f340ea39b07bdfe572d22bd68c97c8d 100644 (file)
@@ -66,7 +66,7 @@ _PUBLIC_ enum MAPISTATUS CreateMessage(mapi_object_t *obj_folder, mapi_object_t
        if ((retval = mapi_object_get_logon_id(obj_folder, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "CreateMessage");
+       mem_ctx = talloc_named(session, 0, "CreateMessage");
        size = 0;
 
        /* Fill the OpenFolder operation */
@@ -157,7 +157,7 @@ _PUBLIC_ enum MAPISTATUS DeleteMessage(mapi_object_t *obj_folder, mapi_id_t *id_
        if ((retval = mapi_object_get_logon_id(obj_folder, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "DeleteMessages");
+       mem_ctx = talloc_named(session, 0, "DeleteMessages");
        size = 0;
 
        /* Fill the DeleteMessages operation */
@@ -245,7 +245,7 @@ _PUBLIC_ enum MAPISTATUS HardDeleteMessage(mapi_object_t *obj_folder,
        if ((retval = mapi_object_get_logon_id(obj_folder, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "HardDeleteMessages");
+       mem_ctx = talloc_named(session, 0, "HardDeleteMessages");
        size = 0;
 
        /* Fill the HardDeleteMessages operation */
@@ -329,7 +329,7 @@ _PUBLIC_ enum MAPISTATUS GetMessageStatus(mapi_object_t *obj_folder,
        if ((retval = mapi_object_get_logon_id(obj_folder, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetMessageStatus");
+       mem_ctx = talloc_named(session, 0, "GetMessageStatus");
        size = 0;
 
        /* Fill the GetMessageStatus operation */
@@ -428,7 +428,7 @@ _PUBLIC_ enum MAPISTATUS SetMessageStatus(mapi_object_t *obj_folder,
        if ((retval = mapi_object_get_logon_id(obj_folder, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SetMessageStatus");
+       mem_ctx = talloc_named(session, 0, "SetMessageStatus");
        size = 0;
 
        /* Fill the SetMessageStatus operation */
@@ -525,7 +525,7 @@ _PUBLIC_ enum MAPISTATUS MoveCopyMessages(mapi_object_t *obj_src,
        if ((retval = mapi_object_get_logon_id(obj_src, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "MoveCopyMessages");
+       mem_ctx = talloc_named(session[0], 0, "MoveCopyMessages");
        size = 0;
 
        /* Fill the CopyMessage operation */
@@ -640,7 +640,7 @@ _PUBLIC_ enum MAPISTATUS CreateFolder(mapi_object_t *obj_parent,
                        ulFolderType != FOLDER_SEARCH),
                       MAPI_E_INVALID_PARAMETER, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "CreateFolder");
+       mem_ctx = talloc_named(session, 0, "CreateFolder");
        size = 0;
 
        /* Fill the CreateFolder operation */
@@ -771,7 +771,7 @@ _PUBLIC_ enum MAPISTATUS EmptyFolder(mapi_object_t *obj_folder)
        if ((retval = mapi_object_get_logon_id(obj_folder, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "EmptyFolder");
+       mem_ctx = talloc_named(session, 0, "EmptyFolder");
        size = 0;
 
        /* Fill the EmptyFolder operation */
@@ -866,7 +866,7 @@ _PUBLIC_ enum MAPISTATUS DeleteFolder(mapi_object_t *obj_parent,
        if ((retval = mapi_object_get_logon_id(obj_parent, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "DeleteFolder");
+       mem_ctx = talloc_named(session, 0, "DeleteFolder");
        size = 0;
 
        /* Fill the DeleteFolder operation */
@@ -962,7 +962,7 @@ _PUBLIC_ enum MAPISTATUS MoveFolder(mapi_object_t *obj_folder,
        if ((retval = mapi_object_get_logon_id(obj_folder, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "MoveFolder");
+       mem_ctx = talloc_named(session[0], 0, "MoveFolder");
        size = 0;
 
        /* Fill the MoveFolder operation */
@@ -1074,7 +1074,7 @@ _PUBLIC_ enum MAPISTATUS CopyFolder(mapi_object_t *obj_folder,
        if ((retval = mapi_object_get_logon_id(obj_folder, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "CopyFolder");
+       mem_ctx = talloc_named(session[0], 0, "CopyFolder");
 
        size = 0;
 
@@ -1183,7 +1183,7 @@ _PUBLIC_ enum MAPISTATUS SetReadFlags(mapi_object_t *obj_folder,
        if ((retval = mapi_object_get_logon_id(obj_folder, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SetReadFlags");
+       mem_ctx = talloc_named(session, 0, "SetReadFlags");
 
        size = 0;
 
@@ -1269,7 +1269,7 @@ _PUBLIC_ enum MAPISTATUS HardDeleteMessagesAndSubfolders(mapi_object_t *obj_fold
        if ((retval = mapi_object_get_logon_id(obj_folder, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "HardDeleteMessagesAndSubfolders");
+       mem_ctx = talloc_named(session, 0, "HardDeleteMessagesAndSubfolders");
        size = 0;
 
        /* Fill the EmptyFolder operation */
index 30764e5a433d3395098f759965d5a4c51882d435..1c5b3bf4bfa31b47321ba055c2ae73b9a5cf5321 100644 (file)
@@ -95,7 +95,7 @@ _PUBLIC_ enum MAPISTATUS GetProps(mapi_object_t *obj,
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetProps");
+       mem_ctx = talloc_named(session, 0, "GetProps");
 
        /* Named property mapping */
        nameid = mapi_nameid_new(mem_ctx);
@@ -225,7 +225,7 @@ _PUBLIC_ enum MAPISTATUS SetProps(mapi_object_t *obj,
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SetProps");
+       mem_ctx = talloc_named(session, 0, "SetProps");
        size = 0;
 
        /* Named property mapping */
@@ -346,7 +346,7 @@ _PUBLIC_ enum MAPISTATUS SaveChangesAttachment(mapi_object_t *obj_parent,
        if ((retval = mapi_object_get_logon_id(obj_parent, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SaveChangesAttachment");
+       mem_ctx = talloc_named(session[0], 0, "SaveChangesAttachment");
        size = 0;
 
        /* Fill the SaveChangesAttachment operation */
@@ -428,7 +428,7 @@ _PUBLIC_ enum MAPISTATUS GetPropList(mapi_object_t *obj,
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetPropList");
+       mem_ctx = talloc_named(session, 0, "GetPropList");
 
        /* Reset */
        proptags->cValues = 0;
@@ -520,7 +520,7 @@ _PUBLIC_ enum MAPISTATUS GetPropsAll(mapi_object_t *obj,
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetPropsAll");
+       mem_ctx = talloc_named(session, 0, "GetPropsAll");
        size = 0;
 
        /* Fill the GetPropsAll operation */
@@ -603,7 +603,7 @@ _PUBLIC_ enum MAPISTATUS DeleteProps(mapi_object_t *obj,
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "DeleteProps");
+       mem_ctx = talloc_named(session, 0, "DeleteProps");
        size = 0;
 
        /* Fill the DeleteProps operation */
@@ -696,7 +696,7 @@ _PUBLIC_ enum MAPISTATUS SetPropertiesNoReplicate(mapi_object_t *obj,
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SetPropertiesNoReplicate");
+       mem_ctx = talloc_named(session, 0, "SetPropertiesNoReplicate");
        size = 0;
 
        /* Named property mapping */
@@ -803,7 +803,7 @@ _PUBLIC_ enum MAPISTATUS DeletePropertiesNoReplicate(mapi_object_t *obj,
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "DeletePropertiesNoReplicate");
+       mem_ctx = talloc_named(session, 0, "DeletePropertiesNoReplicate");
        size = 0;
 
        /* Fill the DeletePropertiesNoReplicate operation */
@@ -893,7 +893,7 @@ _PUBLIC_ enum MAPISTATUS GetNamesFromIDs(mapi_object_t *obj,
                return retval;
 
        /* Initialization */
-       mem_ctx = talloc_named(NULL, 0, "GetNamesFromIDs");
+       mem_ctx = talloc_named(session, 0, "GetNamesFromIDs");
        size = 0;
 
        /* Fill the GetNamesFromIDs operation */
@@ -1005,7 +1005,7 @@ _PUBLIC_ enum MAPISTATUS GetIDsFromNames(mapi_object_t *obj,
                return retval;
 
        /* Initialization */
-       mem_ctx = talloc_named(NULL, 0, "GetIDsFromNames");
+       mem_ctx = talloc_named(session, 0, "GetIDsFromNames");
        size = 0;
        
        /* Fill the GetIDsFromNames operation */
@@ -1119,7 +1119,7 @@ _PUBLIC_ enum MAPISTATUS QueryNamedProperties(mapi_object_t *obj,
                return retval;
 
        /* Initialization */
-       mem_ctx = talloc_named(NULL, 0, "QueryNamesFromIDs");
+       mem_ctx = talloc_named(session, 0, "QueryNamesFromIDs");
        size = 0;
 
        /* Fill the QueryNamedProperties operation */
@@ -1236,7 +1236,7 @@ _PUBLIC_ enum MAPISTATUS CopyProps(mapi_object_t *obj_src,
        if ((retval = mapi_object_get_logon_id(obj_src, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "CopyProps");
+       mem_ctx = talloc_named(session[0], 0, "CopyProps");
        size = 0;
 
        /* Fill the CopyProperties operation */
@@ -1355,7 +1355,7 @@ _PUBLIC_ enum MAPISTATUS CopyTo(mapi_object_t *obj_src,
        if ((retval = mapi_object_get_logon_id(obj_src, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "CopyProps");
+       mem_ctx = talloc_named(session[0], 0, "CopyProps");
        size = 0;
 
        /* Fill the CopyProperties operation */
index 2c712347deb0d4ed3fa0f0dd86c0cdc08ef73d99..0be793e3a27ff24a0371c7fd6c59ace46c20242f 100644 (file)
@@ -50,7 +50,7 @@ static enum MAPISTATUS FindGoodServer(struct mapi_session *session,
        OPENCHANGE_RETVAL_IF(!session->nspi->ctx, MAPI_E_END_OF_SESSION, NULL);
        OPENCHANGE_RETVAL_IF(!legacyDN, MAPI_E_INVALID_PARAMETER, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "FindGoodServer");
+       mem_ctx = talloc_named(session, 0, "FindGoodServer");
        nspi = (struct nspi_context *) session->nspi->ctx;
 
        if (server == false) {
@@ -169,7 +169,7 @@ _PUBLIC_ enum MAPISTATUS OpenPublicFolder(struct mapi_session *session,
        OPENCHANGE_RETVAL_IF(retval, MAPI_E_FAILONEPROVIDER, NULL);
 
 retry:
-       mem_ctx = talloc_named(NULL, 0, "OpenPublicFolder");
+       mem_ctx = talloc_named(session, 0, "OpenPublicFolder");
        size = 0;
 
        /* Fill the Logon operation */
@@ -333,7 +333,7 @@ _PUBLIC_ enum MAPISTATUS OpenUserMailbox(struct mapi_session *session,
        OPENCHANGE_RETVAL_IF(retval, MAPI_E_FAILONEPROVIDER, NULL);
 
 retry:
-       mem_ctx = talloc_named(NULL, 0, "OpenMsgStore");
+       mem_ctx = talloc_named(session, 0, "OpenMsgStore");
        size = 0;
 
        if (!username) {
index f0f588950e67e1bb450dbaecb2ef067581748ce3..6a7541ec6b38faa8057f843f657acfc79a1b59c5 100644 (file)
@@ -101,7 +101,7 @@ _PUBLIC_ enum MAPISTATUS Subscribe(mapi_object_t *obj, uint32_t     *connection,
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "Subscribe");
+       mem_ctx = talloc_named(session, 0, "Subscribe");
 
        /* Fill the Subscribe operation */
        request.handle_idx = 0x1;
index 026503f49ff460a221a8cd55a365d0b4f1313e2a..246d7422f6015c7111bcd93f9b32ac809160b596 100644 (file)
@@ -72,7 +72,7 @@ _PUBLIC_ enum MAPISTATUS SetColumns(mapi_object_t *obj_table,
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SetColumns");
+       mem_ctx = talloc_named(session, 0, "SetColumns");
        size = 0;
 
        /* Fill the SetColumns operation */
@@ -170,7 +170,7 @@ _PUBLIC_ enum MAPISTATUS QueryPosition(mapi_object_t *obj_table,
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "QueryPosition");
+       mem_ctx = talloc_named(session, 0, "QueryPosition");
        size = 0;
 
        /* Fill the MAPI_REQ request */
@@ -267,7 +267,7 @@ _PUBLIC_ enum MAPISTATUS QueryRows(mapi_object_t *obj_table,
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "QueryRows");
+       mem_ctx = talloc_named(session, 0, "QueryRows");
        size = 0;
 
        /* Fill the QueryRows operation */
@@ -360,7 +360,7 @@ _PUBLIC_ enum MAPISTATUS QueryColumns(mapi_object_t *obj_table,
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "QueryColumns");
+       mem_ctx = talloc_named(session, 0, "QueryColumns");
 
        cols->cValues = 0;
        size = 0;
@@ -453,7 +453,7 @@ _PUBLIC_ enum MAPISTATUS SeekRow(mapi_object_t *obj_table,
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SeekRow");
+       mem_ctx = talloc_named(session, 0, "SeekRow");
        *row = 0;
 
        /* Fill the SeekRow operation */
@@ -551,7 +551,7 @@ _PUBLIC_ enum MAPISTATUS SeekRowBookmark(mapi_object_t *obj_table,
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SeekRowBookmark");
+       mem_ctx = talloc_named(session, 0, "SeekRowBookmark");
 
        /* Fill the SeekRowBookmark operation */
        size = 0;
@@ -654,7 +654,7 @@ _PUBLIC_ enum MAPISTATUS SeekRowApprox(mapi_object_t *obj_table,
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SeekRowApprox");
+       mem_ctx = talloc_named(session, 0, "SeekRowApprox");
        
        /* Fill the SeekRowApprox operation */
        size = 0;
@@ -737,7 +737,7 @@ _PUBLIC_ enum MAPISTATUS CreateBookmark(mapi_object_t *obj_table,
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "CreateBookmark");      
+       mem_ctx = talloc_named(session, 0, "CreateBookmark");   
        size = 0;
 
        /* Fill the MAPI_REQ request */
@@ -840,7 +840,7 @@ _PUBLIC_ enum MAPISTATUS FreeBookmark(mapi_object_t *obj_table,
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "FreeBookmark");
+       mem_ctx = talloc_named(session, 0, "FreeBookmark");
 
        while (bookmark) {
                if (bookmark->index == bkPosition) {
@@ -933,7 +933,7 @@ _PUBLIC_ enum MAPISTATUS SortTable(mapi_object_t *obj_table,
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SortTable");
+       mem_ctx = talloc_named(session, 0, "SortTable");
 
        /* Fill the SortTable operation */
        size = 0;
@@ -1079,7 +1079,7 @@ _PUBLIC_ enum MAPISTATUS Reset(mapi_object_t *obj_table)
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "Reset");
+       mem_ctx = talloc_named(session, 0, "Reset");
        size = 0;
 
        /* Fill the MAPI_REQ request */
@@ -1172,7 +1172,7 @@ _PUBLIC_ enum MAPISTATUS Restrict(mapi_object_t *obj_table,
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "Restrict");
+       mem_ctx = talloc_named(session, 0, "Restrict");
 
        /* Fill the Restrict operation */
        size = 0;
@@ -1292,7 +1292,7 @@ _PUBLIC_ enum MAPISTATUS FindRow(mapi_object_t *obj_table,
                OPENCHANGE_RETVAL_IF(retval, MAPI_E_INVALID_BOOKMARK, NULL);
        }
 
-       mem_ctx = talloc_named(NULL, 0, "FindRow");
+       mem_ctx = talloc_named(session, 0, "FindRow");
 
        /* Fill the FindRow operation */
        size = 0;
@@ -1405,7 +1405,7 @@ _PUBLIC_ enum MAPISTATUS GetStatus(mapi_object_t *obj_table, uint8_t *TableStatu
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetStatus");
+       mem_ctx = talloc_named(session, 0, "GetStatus");
        size = 0;
 
        /* Fill the MAPI_REQ request */
@@ -1482,7 +1482,7 @@ _PUBLIC_ enum MAPISTATUS Abort(mapi_object_t *obj_table, uint8_t *TableStatus)
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "Abort");
+       mem_ctx = talloc_named(session, 0, "Abort");
        size = 0;
 
        /* Fill the MAPI_REQ request */
@@ -1591,7 +1591,7 @@ _PUBLIC_ enum MAPISTATUS ExpandRow(mapi_object_t *obj_table,
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "ExpandRow");
+       mem_ctx = talloc_named(session, 0, "ExpandRow");
        size = 0;
 
        /* Fill the ExpandRow operation */
@@ -1694,7 +1694,7 @@ _PUBLIC_ enum MAPISTATUS CollapseRow(mapi_object_t *obj_table, uint64_t category
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "CollapseRow");
+       mem_ctx = talloc_named(session, 0, "CollapseRow");
        size = 0;
 
        /* Fill the CollapseRow operation */
@@ -1788,7 +1788,7 @@ _PUBLIC_ enum MAPISTATUS GetCollapseState(mapi_object_t *obj_table, uint64_t row
 
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
-       mem_ctx = talloc_named(NULL, 0, "GetCollapseState");
+       mem_ctx = talloc_named(session, 0, "GetCollapseState");
        size = 0;
 
        /* Fill the GetCollapseState operation */
@@ -1882,7 +1882,7 @@ _PUBLIC_ enum MAPISTATUS SetCollapseState(mapi_object_t *obj_table,
        if ((retval = mapi_object_get_logon_id(obj_table, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SetCollapseState");
+       mem_ctx = talloc_named(session, 0, "SetCollapseState");
        size = 0;
 
        /* Fill the SetCollapseState operation */
index 178ee4256f0126370f0b564f6193f661d193924d..323c77d6be65eb692e130e0e70dc717ec9896bd6 100644 (file)
@@ -54,7 +54,7 @@ static NTSTATUS provider_rpc_connection(TALLOC_CTX *parent_ctx,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       ev = tevent_context_init(talloc_autofree_context());
+       ev = tevent_context_init(parent_ctx);
        tevent_loop_allow_nesting(ev);
 
        status = dcerpc_pipe_connect(parent_ctx, 
@@ -154,7 +154,7 @@ _PUBLIC_ enum MAPISTATUS RfrGetNewDSA(struct mapi_context *mapi_ctx,
        if (!mapi_ctx) return MAPI_E_NOT_INITIALIZED;
        if (!mapi_ctx->session) return MAPI_E_NOT_INITIALIZED;
 
-       mem_ctx = talloc_named(NULL, 0, "RfrGetNewDSA");
+       mem_ctx = talloc_named(session, 0, "RfrGetNewDSA");
        profile = session->profile;
 
        binding = build_binding_string(mapi_ctx, mem_ctx, server, profile);
index 854b3283a52ac050979e3270ad9e11c0cd27f4b9..d9f6375cd325e5625b009f37a22e187b25d52b12 100644 (file)
@@ -96,7 +96,7 @@ _PUBLIC_ enum MAPISTATUS CreateAttach(mapi_object_t *obj_message,
        if ((retval = mapi_object_get_logon_id(obj_message, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "CreateAttach");
+       mem_ctx = talloc_named(session, 0, "CreateAttach");
        size = 0;
 
        /* Fill the CreateAttach operation */
@@ -180,7 +180,7 @@ _PUBLIC_ enum MAPISTATUS DeleteAttach(mapi_object_t *obj_message, uint32_t Attac
        if ((retval = mapi_object_get_logon_id(obj_message, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "DeleteAttach");
+       mem_ctx = talloc_named(session, 0, "DeleteAttach");
        size = 0;
 
        /* Fill the DeleteAttach operation */
@@ -257,7 +257,7 @@ _PUBLIC_ enum MAPISTATUS GetAttachmentTable(mapi_object_t *obj_message,
        if ((retval = mapi_object_get_logon_id(obj_message, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetAttachmentTable");
+       mem_ctx = talloc_named(session, 0, "GetAttachmentTable");
        size = 0;
 
        /* Fill the GetAttachmentTable operation */
@@ -349,7 +349,7 @@ _PUBLIC_ enum MAPISTATUS GetValidAttach(mapi_object_t *obj_message, uint16_t *Nu
 
        if ((retval = mapi_object_get_logon_id(obj_message, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
-       mem_ctx = talloc_named(NULL, 0, "GetValidAttach");
+       mem_ctx = talloc_named(session, 0, "GetValidAttach");
        size = 0;
 
        /* Fill the MAPI_REQ request */
@@ -428,7 +428,7 @@ _PUBLIC_ enum MAPISTATUS OpenAttach(mapi_object_t *obj_message, uint32_t Attachm
        if ((retval = mapi_object_get_logon_id(obj_message, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "OpenAttach");
+       mem_ctx = talloc_named(session, 0, "OpenAttach");
        size = 0;
 
        /* Fill the OpenAttach operation */
@@ -719,7 +719,7 @@ _PUBLIC_ enum MAPISTATUS ModifyRecipients(mapi_object_t *obj_message,
        if ((retval = mapi_object_get_logon_id(obj_message, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "ModifyRecipients");
+       mem_ctx = talloc_named(session, 0, "ModifyRecipients");
        size = 0;
 
        /* Fill the ModifyRecipients operation */
@@ -961,7 +961,7 @@ _PUBLIC_ enum MAPISTATUS ReadRecipients(mapi_object_t *obj_message,
        if ((retval = mapi_object_get_logon_id(obj_message, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "ReadRecipients");
+       mem_ctx = talloc_named(session, 0, "ReadRecipients");
        size = 0;
 
        /* Fill the ReadRecipients operation */
@@ -1044,7 +1044,7 @@ _PUBLIC_ enum MAPISTATUS RemoveAllRecipients(mapi_object_t *obj_message)
        if ((retval = mapi_object_get_logon_id(obj_message, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "RemoveAllRecipients");
+       mem_ctx = talloc_named(session, 0, "RemoveAllRecipients");
        size = 0;
 
        /* Fill the RemoveAllRecipients operation */
@@ -1124,7 +1124,7 @@ _PUBLIC_ enum MAPISTATUS SubmitMessage(mapi_object_t *obj_message)
        if ((retval = mapi_object_get_logon_id(obj_message, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SubmitMessage");
+       mem_ctx = talloc_named(session, 0, "SubmitMessage");
        size = 0;
 
        /* Fill the SubmitMessage operation */
@@ -1214,7 +1214,7 @@ _PUBLIC_ enum MAPISTATUS AbortSubmit(mapi_object_t *obj_store,
        if ((retval = mapi_object_get_logon_id(obj_store, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "AbortSubmit");
+       mem_ctx = talloc_named(session, 0, "AbortSubmit");
        size = 0;
 
        /* Fill the AbortSubmit operation */
@@ -1308,7 +1308,7 @@ _PUBLIC_ enum MAPISTATUS SaveChangesMessage(mapi_object_t *parent,
        if ((retval = mapi_object_get_logon_id(parent, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SaveChangesMessage");
+       mem_ctx = talloc_named(session, 0, "SaveChangesMessage");
        size = 0;
 
        /* Fill the SaveChangesMessage operation */
@@ -1381,7 +1381,7 @@ _PUBLIC_ enum MAPISTATUS TransportSend(mapi_object_t *obj_message,
        if ((retval = mapi_object_get_logon_id(obj_message, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "TransportSend");
+       mem_ctx = talloc_named(session, 0, "TransportSend");
        size = 0;
 
        /* Fill the MAPI_REQ request */
@@ -1505,7 +1505,7 @@ _PUBLIC_ enum MAPISTATUS SetMessageReadFlag(mapi_object_t *obj_folder,
        if ((retval = mapi_object_get_logon_id(obj_folder, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SetMessageReadFlags");
+       mem_ctx = talloc_named(session[0], 0, "SetMessageReadFlags");
        size = 0;
 
        /* Fill the SetMessageReadFlags operation */
@@ -1647,7 +1647,7 @@ _PUBLIC_ enum MAPISTATUS OpenEmbeddedMessage(mapi_object_t *obj_attach,
        if ((retval = mapi_object_get_logon_id(obj_attach, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "OpenEmbeddedMessage");
+       mem_ctx = talloc_named(session, 0, "OpenEmbeddedMessage");
 
        /* Fill the OpenEmbeddedMessage request */
        request.handle_idx = 0x1;
index b0a5ceb58486b844f78794f4f990b3e07510f299..1e13f4c1390cb924a01e886b60f9f50be05af4bd 100644 (file)
@@ -68,7 +68,7 @@ _PUBLIC_ enum MAPISTATUS OpenFolder(mapi_object_t *obj_store,
        if ((retval = mapi_object_get_logon_id(obj_store, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "OpenFolder");
+       mem_ctx = talloc_named(session, 0, "OpenFolder");
 
        /* Fill the OpenFolder operation */
        request.handle_idx = 0x1;
@@ -163,7 +163,7 @@ _PUBLIC_ enum MAPISTATUS PublicFolderIsGhosted(mapi_object_t *obj_store,
        folderId = mapi_object_get_id(obj_folder);
        OPENCHANGE_RETVAL_IF(!folderId, MAPI_E_INVALID_PARAMETER, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "PublicFolderIsGhosted");
+       mem_ctx = talloc_named(session, 0, "PublicFolderIsGhosted");
        size = 0;
 
        /* Fill the PublicFolderIsGhosted operation */
@@ -245,7 +245,7 @@ _PUBLIC_ enum MAPISTATUS OpenPublicFolderByName(mapi_object_t *obj_folder,
        if ((retval = mapi_object_get_logon_id(obj_folder, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "OpenPublicFolderByName");
+       mem_ctx = talloc_named(session, 0, "OpenPublicFolderByName");
        size = 0;
 
        /* Fill the OpenPublicFolderByName operation */
@@ -335,7 +335,7 @@ _PUBLIC_ enum MAPISTATUS SetReceiveFolder(mapi_object_t *obj_store,
        if ((retval = mapi_object_get_logon_id(obj_store, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SetReceiveFolder");
+       mem_ctx = talloc_named(session, 0, "SetReceiveFolder");
 
        /* Fill the SetReceiveFolder operation */
        size = 0;
@@ -421,7 +421,7 @@ _PUBLIC_ enum MAPISTATUS GetReceiveFolder(mapi_object_t *obj_store,
        if ((retval = mapi_object_get_logon_id(obj_store, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetReceiveFolder");
+       mem_ctx = talloc_named(session, 0, "GetReceiveFolder");
 
        *id_folder = 0;
 
@@ -510,7 +510,7 @@ _PUBLIC_ enum MAPISTATUS GetReceiveFolderTable(mapi_object_t *obj_store,
        if ((retval = mapi_object_get_logon_id(obj_store, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetReceiveFolderTable");
+       mem_ctx = talloc_named(session, 0, "GetReceiveFolderTable");
        size = 0;
 
        /* Fill the MAPI_REQ request */
@@ -611,7 +611,7 @@ _PUBLIC_ enum MAPISTATUS GetTransportFolder(mapi_object_t *obj_store,
        if ((retval = mapi_object_get_logon_id(obj_store, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetTransportFolder");
+       mem_ctx = talloc_named(session, 0, "GetTransportFolder");
        size = 0;
 
        /* Fill the MAPI_REQ request */
@@ -706,7 +706,7 @@ _PUBLIC_ enum MAPISTATUS GetOwningServers(mapi_object_t *obj_store,
        FolderId = mapi_object_get_id(obj_folder);
        OPENCHANGE_RETVAL_IF(!FolderId, MAPI_E_INVALID_PARAMETER, NULL);
                
-       mem_ctx = talloc_named(NULL, 0, "GetOwningServers");
+       mem_ctx = talloc_named(session, 0, "GetOwningServers");
        
        size = 0;
 
@@ -803,7 +803,7 @@ _PUBLIC_ enum MAPISTATUS GetStoreState(mapi_object_t *obj_store,
        if ((retval = mapi_object_get_logon_id(obj_store, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetStoreState");
+       mem_ctx = talloc_named(session, 0, "GetStoreState");
        size = 0;
 
        /* Fill the MAPI_REQ request */
@@ -918,7 +918,7 @@ _PUBLIC_ enum MAPISTATUS TransportNewMail(mapi_object_t *obj_store, mapi_object_
        if ((retval = mapi_object_get_logon_id(obj_folder, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "TransportNewMail");
+       mem_ctx = talloc_named(session, 0, "TransportNewMail");
 
        /* Fill the TransportNewMail operation */
        size = 0;
index 1f83005cdf495423fc8d408e421c06a35d60255f..6117269262f24febe60dd7fedaa90997366fe3ca 100644 (file)
@@ -381,7 +381,7 @@ _PUBLIC_ enum MAPISTATUS mapi_profile_add_string_attr(struct mapi_context *mapi_
        OPENCHANGE_RETVAL_IF(!profile, MAPI_E_BAD_VALUE, NULL);
        OPENCHANGE_RETVAL_IF(!value, MAPI_E_INVALID_PARAMETER, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "mapi_profile_add_string_attr");
+       mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapi_profile_add_string_attr");
        ldb_ctx = mapi_ctx->ldb_ctx;
 
        /* Retrieve the profile from the database */
@@ -441,7 +441,7 @@ _PUBLIC_ enum MAPISTATUS mapi_profile_modify_string_attr(struct mapi_context *ma
        OPENCHANGE_RETVAL_IF(!profname, MAPI_E_BAD_VALUE, NULL);
 
        ldb_ctx = mapi_ctx->ldb_ctx;
-       mem_ctx = talloc_named(NULL, 0, "mapi_profile_modify_string_attr");
+       mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapi_profile_modify_string_attr");
 
        /* Retrieve the profile from the database */
        ret = ldb_search(ldb_ctx, mem_ctx, &res, ldb_get_default_basedn(ldb_ctx), scope, attrs, "(cn=%s)(cn=Profiles)", profname);
@@ -505,7 +505,7 @@ _PUBLIC_ enum MAPISTATUS mapi_profile_delete_string_attr(struct mapi_context *ma
        OPENCHANGE_RETVAL_IF(!profname, MAPI_E_BAD_VALUE, NULL);
 
        ldb_ctx = mapi_ctx->ldb_ctx;
-       mem_ctx = talloc_named(NULL, 0, "mapi_profile_delete_string_attr");
+       mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapi_profile_delete_string_attr");
 
        /* Retrieve the profile from the database */
        ret = ldb_search(ldb_ctx, mem_ctx, &res, ldb_get_default_basedn(ldb_ctx), scope, attrs, "(cn=%s)(cn=Profiles)", profname);
@@ -612,8 +612,8 @@ _PUBLIC_ enum MAPISTATUS CreateProfileStore(const char *profiledb, const char *l
        FILE                    *f;
        struct tevent_context   *ev;
 
-       OPENCHANGE_RETVAL_IF(!profiledb, MAPI_E_CALL_FAILED, NULL);
-       OPENCHANGE_RETVAL_IF(!ldif_path, MAPI_E_CALL_FAILED, NULL);
+       OPENCHANGE_RETVAL_IF(!profiledb, MAPI_E_INVALID_PARAMETER, NULL);
+       OPENCHANGE_RETVAL_IF(!ldif_path, MAPI_E_INVALID_PARAMETER, NULL);
 
        mem_ctx = talloc_named(NULL, 0, "CreateProfileStore");
 
@@ -861,7 +861,7 @@ _PUBLIC_ enum MAPISTATUS CreateProfile(struct mapi_context *mapi_ctx,
        OPENCHANGE_RETVAL_IF(!mapi_ctx, MAPI_E_NOT_INITIALIZED, NULL);
        OPENCHANGE_RETVAL_IF(!mapi_ctx->ldb_ctx, MAPI_E_NOT_INITIALIZED, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "CreateProfile");
+       mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "CreateProfile");
        retval = ldb_create_profile(mem_ctx, mapi_ctx->ldb_ctx, profile);
        OPENCHANGE_RETVAL_IF(retval, retval, mem_ctx);
 
@@ -903,7 +903,7 @@ _PUBLIC_ enum MAPISTATUS DeleteProfile(struct mapi_context *mapi_ctx,
        OPENCHANGE_RETVAL_IF(!mapi_ctx, MAPI_E_NOT_INITIALIZED, NULL);
        OPENCHANGE_RETVAL_IF(!mapi_ctx->ldb_ctx, MAPI_E_NOT_INITIALIZED, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "DeleteProfile");
+       mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "DeleteProfile");
        retval = ldb_delete_profile(mem_ctx, mapi_ctx->ldb_ctx, profile);
        OPENCHANGE_RETVAL_IF(retval, retval, mem_ctx);
        talloc_free(mem_ctx);
@@ -944,7 +944,7 @@ _PUBLIC_ enum MAPISTATUS ChangeProfilePassword(struct mapi_context *mapi_ctx,
        OPENCHANGE_RETVAL_IF(!profile || !old_password || 
                             !password, MAPI_E_INVALID_PARAMETER, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "ChangeProfilePassword");
+       mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "ChangeProfilePassword");
 
        retval = ldb_test_password(mapi_ctx, mem_ctx, profile, password);
        OPENCHANGE_RETVAL_IF(retval, retval, mem_ctx);
@@ -977,7 +977,7 @@ _PUBLIC_ enum MAPISTATUS CopyProfile(struct mapi_context *mapi_ctx,
        OPENCHANGE_RETVAL_IF(!profile_src, MAPI_E_INVALID_PARAMETER, NULL);
        OPENCHANGE_RETVAL_IF(!profile_dst, MAPI_E_INVALID_PARAMETER, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "CopyProfile");
+       mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "CopyProfile");
 
        retval = ldb_copy_profile(mem_ctx, mapi_ctx->ldb_ctx, profile_src, profile_dst);
        OPENCHANGE_RETVAL_IF(retval, retval, mem_ctx);
@@ -1034,7 +1034,7 @@ _PUBLIC_ enum MAPISTATUS DuplicateProfile(struct mapi_context *mapi_ctx,
        retval = OpenProfile(mapi_ctx, &profile, profile_src, NULL);
        OPENCHANGE_RETVAL_IF(retval, MAPI_E_NOT_FOUND, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "DuplicateProfile");
+       mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "DuplicateProfile");
 
        retval = GetProfileAttr(&profile, "username", &count, &attr_tmp);
        OPENCHANGE_RETVAL_IF(retval || !count, MAPI_E_NOT_FOUND, mem_ctx);
@@ -1196,7 +1196,7 @@ _PUBLIC_ enum MAPISTATUS SetDefaultProfile(struct mapi_context *mapi_ctx,
        OPENCHANGE_RETVAL_IF(!mapi_ctx->ldb_ctx, MAPI_E_NOT_INITIALIZED, NULL);
        OPENCHANGE_RETVAL_IF(!profname, MAPI_E_INVALID_PARAMETER, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "SetDefaultProfile");
+       mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "SetDefaultProfile");
 
        /* open profile */
        retval = ldb_load_profile(mem_ctx, mapi_ctx->ldb_ctx, &profile, profname, NULL);
@@ -1299,7 +1299,7 @@ _PUBLIC_ enum MAPISTATUS GetProfileTable(struct mapi_context *mapi_ctx,
        OPENCHANGE_RETVAL_IF(!mapi_ctx, MAPI_E_NOT_INITIALIZED, NULL);
 
        ldb_ctx = mapi_ctx->ldb_ctx;
-       mem_ctx = talloc_autofree_context();
+       mem_ctx = mapi_ctx->mem_ctx;
 
        basedn = ldb_dn_new(ldb_ctx, ldb_ctx, "CN=Profiles");
        ret = ldb_search(ldb_ctx, mem_ctx, &res, basedn, scope, attrs, "(cn=*)");
@@ -1588,7 +1588,7 @@ _PUBLIC_ enum MAPISTATUS ProcessNetworkProfile(struct mapi_session *session,
 
        mapi_ctx = session->mapi_ctx;
 
-       mem_ctx = talloc_named(NULL, 0, "ProcessNetworkProfile");
+       mem_ctx = talloc_named(session, 0, "ProcessNetworkProfile");
        nspi = (struct nspi_context *) session->nspi->ctx;
        profname = session->profile->profname;
        index = 0;
index 65c2185ce306c2da2d7f2438652037929a23b790..4df59d6874ac94e9f136beb235832c83bddd4e8e 100644 (file)
@@ -93,7 +93,7 @@ _PUBLIC_ enum MAPISTATUS OpenMessage(mapi_object_t *obj_store,
        if ((retval = mapi_object_get_logon_id(obj_store, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "OpenMessage");
+       mem_ctx = talloc_named(session, 0, "OpenMessage");
 
        /* Fill the OpenMessage operation */
        request.handle_idx = 0x1;
@@ -232,7 +232,7 @@ _PUBLIC_ enum MAPISTATUS ReloadCachedInformation(mapi_object_t *obj_message)
        if ((retval = mapi_object_get_logon_id(obj_message, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "ReloadCachedInformation");
+       mem_ctx = talloc_named(session, 0, "ReloadCachedInformation");
 
        /* Fill the ReloadCachedInformation operation */
        request.Reserved = 0x0000;
index b3d0d9e0b3908dee763f3710c649b05ed806390f..daa57939bf18aa68fd57097ae2436a73f37ae2ac 100644 (file)
@@ -82,7 +82,7 @@ _PUBLIC_ enum MAPISTATUS OpenStream(mapi_object_t *obj_related, enum MAPITAGS Pr
        if ((retval = mapi_object_get_logon_id(obj_related, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "OpenStream");
+       mem_ctx = talloc_named(session, 0, "OpenStream");
 
        size = 0;
 
@@ -183,7 +183,7 @@ _PUBLIC_ enum MAPISTATUS ReadStream(mapi_object_t *obj_stream, unsigned char *bu
        if ((retval = mapi_object_get_logon_id(obj_stream, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "ReadStream");
+       mem_ctx = talloc_named(session, 0, "ReadStream");
 
        *ByteRead = 0;
        size = 0;
@@ -283,7 +283,7 @@ _PUBLIC_ enum MAPISTATUS WriteStream(mapi_object_t *obj_stream, DATA_BLOB *blob,
        if ((retval = mapi_object_get_logon_id(obj_stream, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "WriteStream");
+       mem_ctx = talloc_named(session, 0, "WriteStream");
 
        size = 0;
 
@@ -364,7 +364,7 @@ _PUBLIC_ enum MAPISTATUS CommitStream(mapi_object_t *obj_stream)
        if ((retval = mapi_object_get_logon_id(obj_stream, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "CommitStream");
+       mem_ctx = talloc_named(session, 0, "CommitStream");
        size = 0;
 
        /* Fill the MAPI_REQ request */
@@ -435,7 +435,7 @@ _PUBLIC_ enum MAPISTATUS GetStreamSize(mapi_object_t *obj_stream, uint32_t *Stre
        if ((retval = mapi_object_get_logon_id(obj_stream, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "GetStreamSize");
+       mem_ctx = talloc_named(session, 0, "GetStreamSize");
        size = 0;
 
        /* Fill the MAPI_REQ request */
@@ -523,7 +523,7 @@ _PUBLIC_ enum MAPISTATUS SeekStream(mapi_object_t *obj_stream, uint8_t Origin, u
        if ((retval = mapi_object_get_logon_id(obj_stream, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SeekStream");
+       mem_ctx = talloc_named(session, 0, "SeekStream");
        size = 0;
 
        /* Fill the SeekStream operation */
@@ -604,7 +604,7 @@ _PUBLIC_ enum MAPISTATUS SetStreamSize(mapi_object_t *obj_stream, uint64_t SizeS
        if ((retval = mapi_object_get_logon_id(obj_stream, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SetStreamSize");
+       mem_ctx = talloc_named(session, 0, "SetStreamSize");
        size = 0;
 
        /* Fill the SetStreamSize operation */
@@ -699,7 +699,7 @@ _PUBLIC_ enum MAPISTATUS CopyToStream(mapi_object_t *obj_src, mapi_object_t *obj
        if ((retval = mapi_object_get_logon_id(obj_src, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "CopyToStream");
+       mem_ctx = talloc_named(session[0], 0, "CopyToStream");
        size = 0;
 
        /* Fill the CopyToStream operation */
@@ -789,7 +789,7 @@ _PUBLIC_ enum MAPISTATUS LockRegionStream(mapi_object_t *obj_stream, uint64_t Re
        if ((retval = mapi_object_get_logon_id(obj_stream, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "LockRegionStream");
+       mem_ctx = talloc_named(session, 0, "LockRegionStream");
        size = 0;
 
        /* Fill the LockRegionStream operation */
@@ -871,7 +871,7 @@ _PUBLIC_ enum MAPISTATUS UnlockRegionStream(mapi_object_t *obj_stream, uint64_t
        if ((retval = mapi_object_get_logon_id(obj_stream, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "UnlockRegionStream");
+       mem_ctx = talloc_named(session, 0, "UnlockRegionStream");
        size = 0;
 
        /* Fill the LockRegionStream operation */
@@ -950,7 +950,7 @@ _PUBLIC_ enum MAPISTATUS CloneStream(mapi_object_t *obj_src, mapi_object_t *obj_
        if ((retval = mapi_object_get_logon_id(obj_src, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "CloneStream");
+       mem_ctx = talloc_named(session, 0, "CloneStream");
        size = 0;
 
        /* Fill the CloneStream operation */
@@ -1042,7 +1042,7 @@ _PUBLIC_ enum MAPISTATUS WriteAndCommitStream(mapi_object_t *obj_stream, DATA_BL
        if ((retval = mapi_object_get_logon_id(obj_stream, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "WriteAndCommitStream");
+       mem_ctx = talloc_named(session, 0, "WriteAndCommitStream");
 
        size = 0;
 
index b09d77e9422b454f6f6b62ff4d68c76826995288..44c1eb60cef7969574663fb9d5431082fe295ed4 100644 (file)
@@ -129,7 +129,7 @@ _PUBLIC_ enum MAPISTATUS Release(mapi_object_t *obj)
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "Release");
+       mem_ctx = talloc_named(session, 0, "Release");
 
        /* Fill the MAPI_REQ request */
        mapi_req = talloc_zero(mem_ctx, struct EcDoRpc_MAPI_REQ);
@@ -220,7 +220,7 @@ _PUBLIC_ enum MAPISTATUS GetLongTermIdFromId(mapi_object_t *obj, mapi_id_t id,
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "LongTermIdFromId");
+       mem_ctx = talloc_named(session, 0, "LongTermIdFromId");
 
        /* Fill the LongTermIdFromId operation */
        request.Id = id;
@@ -306,7 +306,7 @@ _PUBLIC_ enum MAPISTATUS GetIdFromLongTermId(mapi_object_t *obj, struct LongTerm
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "IdFromLongTermId");
+       mem_ctx = talloc_named(session, 0, "IdFromLongTermId");
        size = 0;
 
        /* Fill the IdFromLongTermId operation */
index 26f6810f7fb23596a2827fa26c8cf40f1750c24c..451cbd23081d848a7a0184a6cb3b85c6d663a1f4 100644 (file)
@@ -71,7 +71,7 @@ _PUBLIC_ enum MAPISTATUS AddressTypes(mapi_object_t *obj_store,
        if ((retval = mapi_object_get_logon_id(obj_store, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "AddressTypes");
+       mem_ctx = talloc_named(session, 0, "AddressTypes");
        size = 0;
 
        /* Fill the MAPI_REQ request */
@@ -146,7 +146,7 @@ _PUBLIC_ enum MAPISTATUS SetSpooler(mapi_object_t *obj_store)
        if ((retval = mapi_object_get_logon_id(obj_store, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SetSpooler");
+       mem_ctx = talloc_named(session, 0, "SetSpooler");
        size = 0;
 
        /* Fill the MAPI_REQ request */
@@ -228,7 +228,7 @@ _PUBLIC_ enum MAPISTATUS SpoolerLockMessage(mapi_object_t *obj_store,
        if ((retval = mapi_object_get_logon_id(obj_store, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "SpoolerLockMessage");
+       mem_ctx = talloc_named(session, 0, "SpoolerLockMessage");
        size = 0;
 
        /* Fill the SpoolerLockMessage operation */
@@ -318,7 +318,7 @@ _PUBLIC_ enum MAPISTATUS OptionsData(mapi_object_t *obj_store, const char *addrt
        if ((retval = mapi_object_get_logon_id(obj_store, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, "RecipientOptions");
+       mem_ctx = talloc_named(session, 0, "RecipientOptions");
        size = 0;
 
        /* Build the OptionsData request */
index d09c82806528d0af7a5a9ad4e4f4847872a9a796..3a1a52c7477ff157d7c9e230957013104628a5b3 100644 (file)
@@ -333,7 +333,7 @@ _PUBLIC_ enum MAPISTATUS SetMAPIDebugLevel(struct mapi_context *mapi_ctx, uint32
        /* Sanity checks */
        OPENCHANGE_RETVAL_IF(!mapi_ctx, MAPI_E_NOT_INITIALIZED, NULL);
 
-       debuglevel = talloc_asprintf(talloc_autofree_context(), "%u", level);
+       debuglevel = talloc_asprintf(mapi_ctx->mem_ctx, "%u", level);
        ret = lpcfg_set_cmdline(mapi_ctx->lp_ctx, "log level", debuglevel);
        talloc_free(debuglevel);
 
index 4e6dc565586a94204a19d05dfb69f96aa11c35e7..238fbfc5e4e808d32dd53dd4a68cf960c4a79837 100644 (file)
@@ -96,7 +96,7 @@ struct emsmdb_context *emsmdb_connect(TALLOC_CTX *parent_mem_ctx,
        if (!return_value) return NULL;
        if (!session->profile->mailbox) return NULL;
 
-       mem_ctx = talloc_named(NULL, 0, "emsmdb_connect");
+       mem_ctx = talloc_named(parent_mem_ctx, 0, "emsmdb_connect");
 
        ret = talloc_zero(parent_mem_ctx, struct emsmdb_context);
        ret->rpc_connection = p;
@@ -189,7 +189,7 @@ struct emsmdb_context *emsmdb_connect_ex(TALLOC_CTX *mem_ctx,
        if (!cred) return NULL;
        if (!return_value) return NULL;
 
-       tmp_ctx = talloc_named(NULL, 0, "emsmdb_connect_ex");
+       tmp_ctx = talloc_named(mem_ctx, 0, "emsmdb_connect_ex");
 
        ctx = talloc_zero(mem_ctx, struct emsmdb_context);
        ctx->rpc_connection = p;
@@ -700,7 +700,7 @@ NTSTATUS emsmdb_register_notification(struct mapi_session *session,
 
        emsmdb_ctx = (struct emsmdb_context *)session->emsmdb->ctx;
        notify_ctx = (struct mapi_notify_ctx *)session->notify_ctx;
-       mem_ctx = talloc_named(NULL, 0, "emsmdb_register_notification");
+       mem_ctx = talloc_named(session, 0, "emsmdb_register_notification");
 
        request.in.handle = &emsmdb_ctx->handle;
        request.in.iRpc = 0x0;
index 6b885eef831e31352d325bb1a3414e8cef94b2c2..d877111c24ade31739d8b637bdbcea32863e44e0 100644 (file)
@@ -74,7 +74,7 @@ _PUBLIC_ enum MAPISTATUS SyncOpenAdvisor(mapi_object_t *obj, mapi_object_t *obj_
        if ((retval = mapi_object_get_logon_id(obj, &logon_id)) != MAPI_E_SUCCESS)
                return retval;
 
-       mem_ctx = talloc_named(NULL, 0, __FUNCTION__);
+       mem_ctx = talloc_named(session, 0, __FUNCTION__);
 
        /* Fill the SyncOpenAdvisor operation */
        request.handle_idx = 0x01;
@@ -158,7 +158,7 @@ _PUBLIC_ enum MAPISTATUS SetSyncNotificationGuid(mapi_object_t *obj_advisor,
                return retval;
        }
 
-       mem_ctx = talloc_named(NULL, 0, __FUNCTION__);
+       mem_ctx = talloc_named(session, 0, __FUNCTION__);
 
        /* Fill the SetSyncNotificationGuid operation */
        request.NotificationGuid = Guid;
index e076480181978944f4532cab5ecca9707c2bb8cb..feef9035514674ec4dfa1875f1b7d9a50765a7a1 100644 (file)
@@ -103,7 +103,7 @@ _PUBLIC_ struct nspi_context *nspi_bind(TALLOC_CTX *parent_ctx,
                return NULL;
        }
 
-       mem_ctx = talloc_named(NULL, 0, __FUNCTION__);
+       mem_ctx = talloc_named(parent_ctx, 0, __FUNCTION__);
 
        r.in.dwFlags = 0;
 
index 182122584610c0595abaceea65112d4f4d74406c..00803daeaba0fc23f871b9e07f056b3264985b31 100644 (file)
@@ -876,7 +876,7 @@ _PUBLIC_ uint32_t cast_SPropValue(TALLOC_CTX *mem_ctx,
        {
                DATA_BLOB       b;
                
-               GUID_to_ndr_blob(&(mapi_sprop->value.lpguid), talloc_autofree_context(), &b);
+               GUID_to_ndr_blob(&(mapi_sprop->value.lpguid), mem_ctx, &b);
                sprop->value.lpguid = talloc_zero(mem_ctx, struct FlatUID_r);
                sprop->value.lpguid = (struct FlatUID_r *)memcpy(sprop->value.lpguid->ab, b.data, 16);
                return (sizeof (struct FlatUID_r));
@@ -958,7 +958,7 @@ _PUBLIC_ uint32_t cast_SPropValue(TALLOC_CTX *mem_ctx,
                        DATA_BLOB       b;
                        
                        sprop->value.MVguid.lpguid[i] = talloc_zero(mem_ctx, struct FlatUID_r);
-                       GUID_to_ndr_blob(&(mapi_sprop->value.MVguid.lpguid[i]), talloc_autofree_context(), &b);
+                       GUID_to_ndr_blob(&(mapi_sprop->value.MVguid.lpguid[i]), mem_ctx, &b);
                        sprop->value.MVguid.lpguid[i] = (struct FlatUID_r *)memcpy(sprop->value.MVguid.lpguid[i]->ab, b.data, sizeof(struct FlatUID_r));
                        size += (sizeof (struct FlatUID_r));
                }
@@ -1080,7 +1080,7 @@ _PUBLIC_ void mapi_SPropValue_array_named(mapi_object_t *obj,
        uint16_t                count;
        uint32_t                i;
 
-       mem_ctx = talloc_named(NULL, 0, "mapi_SPropValue_array_named");
+       mem_ctx = talloc_named(mapi_object_get_session(obj), 0, "mapi_SPropValue_array_named");
 
        for (i = 0; i < props->cValues; i++) {
                if ((props->lpProps[i].ulPropTag & 0xFFFF0000) > 0x80000000) {
index adcd1f72f581d0394238c67dc6f771fe06aeae64..33bae82cb866bbd0ce484d9172f34c0e11cb6af6 100644 (file)
@@ -124,7 +124,7 @@ static enum MAPISTATUS CacheDefaultFolders(mapi_object_t *obj_store)
        store = (mapi_object_store_t *)obj_store->private_data;
        OPENCHANGE_RETVAL_IF(!store, MAPI_E_NOT_INITIALIZED, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "CacheDefaultFolders");
+       mem_ctx = talloc_named(mapi_object_get_session(obj_store), 0, "CacheDefaultFolders");
 
        mapi_object_init(&obj_inbox);
        retval = GetReceiveFolder(obj_store, &id_inbox, NULL);
@@ -430,7 +430,7 @@ _PUBLIC_ enum MAPISTATUS GetFolderItemsCount(mapi_object_t *obj_folder,
        OPENCHANGE_RETVAL_IF(!unread, MAPI_E_INVALID_PARAMETER, NULL);
        OPENCHANGE_RETVAL_IF(!total, MAPI_E_INVALID_PARAMETER, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "GetFolderItemsCount");
+       mem_ctx = talloc_named(mapi_object_get_session(obj_folder), 0, "GetFolderItemsCount");
 
        SPropTagArray = set_SPropTagArray(mem_ctx, 0x2, 
                                          PR_CONTENT_UNREAD,
@@ -504,7 +504,7 @@ _PUBLIC_ enum MAPISTATUS AddUserPermission(mapi_object_t *obj_folder, const char
 
        rowList.ModifyFlags = 0;
 
-       mem_ctx = talloc_named(NULL, 0, "AddUserPermission");
+       mem_ctx = talloc_named(mapi_object_get_session(obj_folder), 0, "AddUserPermission");
 
        /* query Address book */
 
@@ -585,7 +585,7 @@ _PUBLIC_ enum MAPISTATUS ModifyUserPermission(mapi_object_t *obj_folder,
 
        rowList.ModifyFlags = 0;
 
-       mem_ctx = talloc_named(NULL, 0, "ModifyUserPermission");
+       mem_ctx = talloc_named(mapi_object_get_session(obj_folder), 0, "ModifyUserPermission");
 
        SPropTagArray = set_SPropTagArray(mem_ctx, 2, PR_ENTRYID, PR_DISPLAY_NAME);
        names[0] = username;
@@ -701,7 +701,7 @@ _PUBLIC_ enum MAPISTATUS RemoveUserPermission(mapi_object_t *obj_folder,
        OPENCHANGE_RETVAL_IF(!obj_folder, MAPI_E_INVALID_PARAMETER, NULL);
        OPENCHANGE_RETVAL_IF(!username, MAPI_E_INVALID_PARAMETER, NULL);
 
-       mem_ctx = talloc_named(NULL, 0, "RemoveUserPermission");
+       mem_ctx = talloc_named(mapi_object_get_session(obj_folder), 0, "RemoveUserPermission");
 
        SPropTagArray = set_SPropTagArray(mem_ctx, 2, PR_ENTRYID, PR_DISPLAY_NAME);
        names[0] = username;
index 55310462dbbfba9c5890d559e39a423ea4a16ce4..b3331ebd7f6c067b9b54af16f4597e9d428c596c 100644 (file)
@@ -55,7 +55,7 @@ static const struct exchange_version exchange_version[] = {
 static bool mapiprofile_createdb(const char *profdb, const char *ldif_path)
 {
        enum MAPISTATUS retval;
-       
+
        if (access(profdb, F_OK) == 0) {
                fprintf(stderr, "[ERROR] mapiprofile: %s already exists\n", profdb);
                return false;
@@ -63,9 +63,10 @@ static bool mapiprofile_createdb(const char *profdb, const char *ldif_path)
 
        retval = CreateProfileStore(profdb, ldif_path);
        if (retval != MAPI_E_SUCCESS) {
-               mapi_errstr("CreateProfileStore", GetLastError());
+               mapi_errstr("CreateProfileStore", retval);
                return false;
        }
+
        return true;
 }
 
@@ -113,14 +114,15 @@ static void signal_delete_profile(void)
 
        fprintf(stderr, "CTRL-C caught ... Deleting profile\n");
        if ((retval = DeleteProfile(g_mapi_ctx, g_profname)) != MAPI_E_SUCCESS) {
-               mapi_errstr("DeleteProfile", GetLastError());
+               mapi_errstr("DeleteProfile", retval);
        }
 
        (void) signal(SIGINT, SIG_DFL);
        exit (1);
 }
 
-static bool mapiprofile_create(const char *profdb, const char *profname,
+static bool mapiprofile_create(struct mapi_context *mapi_ctx,
+                              const char *profdb, const char *profname,
                               const char *pattern, const char *username, 
                               const char *password, const char *address, 
                               const char *language, const char *workstation,
@@ -130,7 +132,6 @@ static bool mapiprofile_create(const char *profdb, const char *profname,
                               uint8_t exchange_version, const char *kerberos)
 {
        enum MAPISTATUS         retval;
-       struct mapi_context     *mapi_ctx;
        struct mapi_session     *session = NULL;
        TALLOC_CTX              *mem_ctx;
        struct mapi_profile     profile;
@@ -141,14 +142,7 @@ static bool mapiprofile_create(const char *profdb, const char *profname,
        char                    *cpid_str;
        char                    *lcid_str;
 
-       mem_ctx = talloc_named(NULL, 0, "mapiprofile_create");
-
-       retval = MAPIInitialize(&mapi_ctx, profdb);
-       if (retval != MAPI_E_SUCCESS) {
-               mapi_errstr("MAPIInitialize", GetLastError());
-               talloc_free(mem_ctx);
-               return false;
-       }
+       mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapiprofile_create");
 
        /* catch CTRL-C */
        g_profname = profname;
@@ -173,14 +167,13 @@ static bool mapiprofile_create(const char *profdb, const char *profname,
        retval = OpenProfile(mapi_ctx, &profile, profname, NULL);
        if (retval == MAPI_E_SUCCESS) {
                fprintf(stderr, "[ERROR] mapiprofile: profile \"%s\" already exists\n", profname);
-               MAPIUninitialize(mapi_ctx);
                talloc_free(mem_ctx);
                return false;
        }
 
        retval = CreateProfile(mapi_ctx, profname, username, password, flags);
        if (retval != MAPI_E_SUCCESS) {
-               mapi_errstr("CreateProfile", GetLastError());
+               mapi_errstr("CreateProfile", retval);
                talloc_free(mem_ctx);
                return false;
        }
@@ -209,7 +202,7 @@ static bool mapiprofile_create(const char *profdb, const char *profname,
                printf("Invalid Language supplied or unknown system language '%s\n'", language);
                printf("Deleting profile\n");
                if ((retval = DeleteProfile(mapi_ctx, profname)) != MAPI_E_SUCCESS) {
-                       mapi_errstr("DeleteProfile", GetLastError());
+                       mapi_errstr("DeleteProfile", retval);
                }
                talloc_free(mem_ctx);
                return false;
@@ -231,10 +224,10 @@ static bool mapiprofile_create(const char *profdb, const char *profname,
 
        retval = MapiLogonProvider(mapi_ctx, &session, profname, password, PROVIDER_ID_NSPI);
        if (retval != MAPI_E_SUCCESS) {
-               mapi_errstr("MapiLogonProvider", GetLastError());
+               mapi_errstr("MapiLogonProvider", retval);
                printf("Deleting profile\n");
                if ((retval = DeleteProfile(mapi_ctx, profname)) != MAPI_E_SUCCESS) {
-                       mapi_errstr("DeleteProfile", GetLastError());
+                       mapi_errstr("DeleteProfile", retval);
                }
                talloc_free(mem_ctx);
                return false;
@@ -246,10 +239,10 @@ static bool mapiprofile_create(const char *profdb, const char *profname,
 
        retval = ProcessNetworkProfile(session, username, (mapi_profile_callback_t) callback, "Select a user id");
        if (retval != MAPI_E_SUCCESS && retval != 0x1) {
-               mapi_errstr("ProcessNetworkProfile", GetLastError());
+               mapi_errstr("ProcessNetworkProfile", retval);
                printf("Deleting profile\n");
                if ((retval = DeleteProfile(mapi_ctx, profname)) != MAPI_E_SUCCESS) {
-                       mapi_errstr("DeleteProfile", GetLastError());
+                       mapi_errstr("DeleteProfile", retval);
                }
                talloc_free(mem_ctx);
                return false;
@@ -259,45 +252,29 @@ static bool mapiprofile_create(const char *profdb, const char *profname,
 
        talloc_free(mem_ctx);
 
-       MAPIUninitialize(mapi_ctx);
-
        return true;
 }
 
-static void mapiprofile_delete(const char *profdb, const char *profname)
+static void mapiprofile_delete(struct mapi_context *mapi_ctx, const char *profdb, const char *profname)
 {
        enum MAPISTATUS         retval;
-       struct mapi_context     *mapi_ctx;
-
-       if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
-               mapi_errstr("MAPIInitialize", GetLastError());
-               exit (1);
-       }
 
        if ((retval = DeleteProfile(mapi_ctx, profname)) != MAPI_E_SUCCESS) {
-               mapi_errstr("DeleteProfile", GetLastError());
+               mapi_errstr("DeleteProfile", retval);
                exit (1);
        }
 
        printf("Profile %s deleted from database %s\n", profname, profdb);
-
-       MAPIUninitialize(mapi_ctx);
 }
 
 
-static void mapiprofile_rename(const char *profdb, const char *old_profname, const char *new_profname)
+static void mapiprofile_rename(struct mapi_context *mapi_ctx, const char *profdb, const char *old_profname, const char *new_profname)
 {
        TALLOC_CTX              *mem_ctx;
        enum MAPISTATUS         retval;
-       struct mapi_context     *mapi_ctx;
        char                    *profname;
 
-       if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
-               mapi_errstr("MAPIInitialize", retval);
-               exit (1);
-       }
-
-       mem_ctx = talloc_named(NULL, 0, "mapiprofile_rename");
+       mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapiprofile_rename");
 
        if (!old_profname) {
                if ((retval = GetDefaultProfile(mapi_ctx, &profname)) != MAPI_E_SUCCESS) {
@@ -318,76 +295,55 @@ static void mapiprofile_rename(const char *profdb, const char *old_profname, con
 
        talloc_free(profname);
        talloc_free(mem_ctx);
-       MAPIUninitialize(mapi_ctx);
 }
 
 
-static void mapiprofile_set_default(const char *profdb, const char *profname)
+static void mapiprofile_set_default(struct mapi_context *mapi_ctx, const char *profdb, const char *profname)
 {
        enum MAPISTATUS         retval;
-       struct mapi_context     *mapi_ctx;
-
-       if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
-               mapi_errstr("MAPIInitialize", GetLastError());
-               exit (1);
-       }
 
        if ((retval = SetDefaultProfile(mapi_ctx, profname)) != MAPI_E_SUCCESS) {
-               mapi_errstr("SetDefaultProfile", GetLastError());
+               mapi_errstr("SetDefaultProfile", retval);
                exit (1);
        }
 
        printf("Profile %s is now set the default one\n", profname);
-
-       MAPIUninitialize(mapi_ctx);
 }
 
-static void mapiprofile_get_default(const char *profdb)
+static void mapiprofile_get_default(struct mapi_context *mapi_ctx, const char *profdb)
 {
        enum MAPISTATUS         retval;
-       struct mapi_context     *mapi_ctx;
        char                    *profname;
 
-       if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
-               mapi_errstr("MAPIInitialize", GetLastError());
-               exit (1);
-       }
-       
        if ((retval = GetDefaultProfile(mapi_ctx, &profname)) != MAPI_E_SUCCESS) {
-               mapi_errstr("GetDefaultProfile", GetLastError());
+               mapi_errstr("GetDefaultProfile", retval);
                exit (1);
        }
 
        printf("Default profile is set to %s\n", profname);
 
        talloc_free(profname);
-       MAPIUninitialize(mapi_ctx);
 }
 
-static void mapiprofile_get_fqdn(const char *profdb, 
-                                const char *opt_profname, 
+static void mapiprofile_get_fqdn(struct mapi_context *mapi_ctx,
+                                const char *profdb,
+                                const char *opt_profname,
                                 const char *password,
                                 bool opt_dumpdata)
 {
        TALLOC_CTX              *mem_ctx;
        enum MAPISTATUS         retval;
-       struct mapi_context     *mapi_ctx;
        struct mapi_session     *session = NULL;
        const char              *serverFQDN;
        char                    *profname;
 
-       if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
-               mapi_errstr("MAPIInitialize", GetLastError());
-               exit (1);
-       }
-
        SetMAPIDumpData(mapi_ctx, opt_dumpdata);
 
-       mem_ctx = talloc_named(NULL, 0, "mapiprofile_get_fqdn");
+       mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapiprofile_get_fqdn");
 
        if (!opt_profname) {
                if ((retval = GetDefaultProfile(mapi_ctx, &profname)) != MAPI_E_SUCCESS) {
-                       mapi_errstr("GetDefaultProfile", GetLastError());
+                       mapi_errstr("GetDefaultProfile", retval);
                        talloc_free(mem_ctx);
                        exit (1);
                }
@@ -399,36 +355,28 @@ static void mapiprofile_get_fqdn(const char *profdb,
        talloc_free(profname);
        talloc_free(mem_ctx);
        if (retval != MAPI_E_SUCCESS) {
-               mapi_errstr("MapiLogonProvider", GetLastError());
+               mapi_errstr("MapiLogonProvider", retval);
                exit (1);
        }
 
        retval = RfrGetFQDNFromLegacyDN(mapi_ctx, session, &serverFQDN);
        if (retval != MAPI_E_SUCCESS) {
-               mapi_errstr("RfrGetFQDNFromLegacyDN", GetLastError());
+               mapi_errstr("RfrGetFQDNFromLegacyDN", retval);
                exit (1);
        }
 
        printf("%s is at %s\n", mapi_ctx->session->profile->homemdb, serverFQDN);
-
-       MAPIUninitialize(mapi_ctx);
 }
 
-static void mapiprofile_list(const char *profdb)
+static void mapiprofile_list(struct mapi_context *mapi_ctx, const char *profdb)
 {
        enum MAPISTATUS         retval;
-       struct mapi_context     *mapi_ctx;
        struct SRowSet          proftable;
        uint32_t                count = 0;
 
-       if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
-               mapi_errstr("MAPIInitialize", GetLastError());
-               exit (1);
-       }
-
        memset(&proftable, 0, sizeof (struct SRowSet));
        if ((retval = GetProfileTable(mapi_ctx, &proftable)) != MAPI_E_SUCCESS) {
-               mapi_errstr("GetProfileTable", GetLastError());
+               mapi_errstr("GetProfileTable", retval);
                exit (1);
        }
 
@@ -448,29 +396,21 @@ static void mapiprofile_list(const char *profdb)
                }
 
        }
-
-       MAPIUninitialize(mapi_ctx);
 }
 
-static void mapiprofile_dump(const char *profdb, const char *opt_profname)
+static void mapiprofile_dump(struct mapi_context *mapi_ctx, const char *profdb, const char *opt_profname)
 {
        TALLOC_CTX              *mem_ctx;
        enum MAPISTATUS         retval;
-       struct mapi_context     *mapi_ctx;
        struct mapi_profile     profile;
        char                    *profname;
        char                    *exchange_version = NULL;
 
-       if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
-               mapi_errstr("MAPIInitialize", GetLastError());
-               exit (1);
-       }
-
-       mem_ctx = talloc_named(NULL, 0, "mapiprofile_dump");
+       mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapiprofile_dump");
 
        if (!opt_profname) {
                if ((retval = GetDefaultProfile(mapi_ctx, &profname)) != MAPI_E_SUCCESS) {
-                       mapi_errstr("GetDefaultProfile", GetLastError());
+                       mapi_errstr("GetDefaultProfile", retval);
                        talloc_free(mem_ctx);
                        exit (1);
                }
@@ -483,7 +423,7 @@ static void mapiprofile_dump(const char *profdb, const char *opt_profname)
 
        if (retval && (retval != MAPI_E_INVALID_PARAMETER)) {
                talloc_free(mem_ctx);
-               mapi_errstr("OpenProfile", GetLastError());
+               mapi_errstr("OpenProfile", retval);
                exit (1);
        }
 
@@ -514,31 +454,24 @@ static void mapiprofile_dump(const char *profdb, const char *opt_profname)
 
 end:
        talloc_free(mem_ctx);
-       MAPIUninitialize(mapi_ctx);
 }
 
-static void mapiprofile_attribute(const char *profdb, const char *opt_profname, 
+static void mapiprofile_attribute(struct mapi_context *mapi_ctx, const char *profdb, const char *opt_profname, 
                                  const char *attribute)
 {
        TALLOC_CTX              *mem_ctx;
        enum MAPISTATUS         retval;
-       struct mapi_context     *mapi_ctx;
        struct mapi_profile     profile;
        char                    *profname = NULL;
        char                    **value = NULL;
        unsigned int            count = 0;
        unsigned int            i;
 
-       if ((retval = MAPIInitialize(&mapi_ctx, profdb)) != MAPI_E_SUCCESS) {
-               mapi_errstr("MAPIInitialize", GetLastError());
-               exit (1);
-       }
-
-       mem_ctx = talloc_named(NULL, 0, "mapiprofile_attribute");
+       mem_ctx = talloc_named(mapi_ctx->mem_ctx, 0, "mapiprofile_attribute");
 
        if (!opt_profname) {
                if ((retval = GetDefaultProfile(mapi_ctx, &profname)) != MAPI_E_SUCCESS) {
-                       mapi_errstr("GetDefaultProfile", GetLastError());
+                       mapi_errstr("GetDefaultProfile", retval);
                        exit (1);
                }
        } else {
@@ -547,14 +480,14 @@ static void mapiprofile_attribute(const char *profdb, const char *opt_profname,
 
        retval = OpenProfile(mapi_ctx, &profile, profname, NULL);
        if (retval && (retval != MAPI_E_INVALID_PARAMETER)) {
-               mapi_errstr("OpenProfile", GetLastError());
+               mapi_errstr("OpenProfile", retval);
                talloc_free(profname);
                talloc_free(mem_ctx);
                exit (1);
        }
 
        if ((retval = GetProfileAttr(&profile, attribute, &count, &value))) {
-               mapi_errstr("ProfileGetAttr", GetLastError());
+               mapi_errstr("ProfileGetAttr", retval);
                talloc_free(profname);
                talloc_free(mem_ctx);
                exit (1);
@@ -567,8 +500,6 @@ static void mapiprofile_attribute(const char *profdb, const char *opt_profname,
        MAPIFreeBuffer(value);
        talloc_free(profname);
        talloc_free(mem_ctx);
-
-       MAPIUninitialize(mapi_ctx);
 }
 
 static void show_help(poptContext pc, const char *param)
@@ -581,6 +512,7 @@ static void show_help(poptContext pc, const char *param)
 int main(int argc, const char *argv[])
 {
        TALLOC_CTX      *mem_ctx;
+       struct mapi_context *mapi_ctx = NULL;
        int             error;
        poptContext     pc;
        int             opt;
@@ -802,6 +734,11 @@ int main(int argc, const char *argv[])
                }
        }
 
+       if (MAPIInitialize(&mapi_ctx, profdb) != MAPI_E_SUCCESS) {
+               mapi_errstr("MAPIInitialize", GetLastError());
+               exit (1);
+       }
+
        if (opt_krb) {
                if (strncmp(opt_krb, "yes", 3) && strncmp(opt_krb, "no", 2)) {
                        fprintf(stderr,
@@ -851,7 +788,7 @@ int main(int argc, const char *argv[])
                }
                talloc_free((void *)version);
 
-               if (! mapiprofile_create(profdb, profname, pattern, username, password, address,
+               if (! mapiprofile_create(mapi_ctx, profdb, profname, pattern, username, password, address,
                                         language, workstation, domain, realm, nopass, opt_seal, 
                                         opt_dumpdata, opt_debuglevel,
                                         exchange_version[i].version,
@@ -862,11 +799,11 @@ int main(int argc, const char *argv[])
        }
 
        if (rename) {
-               mapiprofile_rename(profdb, profname, rename);
+               mapiprofile_rename(mapi_ctx, profdb, profname, rename);
        }
 
        if (getfqdn == true) {
-               mapiprofile_get_fqdn(profdb, profname, password, opt_dumpdata);
+               mapiprofile_get_fqdn(mapi_ctx, profdb, profname, password, opt_dumpdata);
        }
 
        if (listlangs == true) {
@@ -874,27 +811,27 @@ int main(int argc, const char *argv[])
        }
 
        if (setdflt == true) {
-               mapiprofile_set_default(profdb, profname);
+               mapiprofile_set_default(mapi_ctx, profdb, profname);
        }
 
        if (getdflt == true) {
-               mapiprofile_get_default(profdb);
+               mapiprofile_get_default(mapi_ctx, profdb);
        }
 
        if (delete == true) {
-               mapiprofile_delete(profdb, profname);
+               mapiprofile_delete(mapi_ctx, profdb, profname);
        }
 
        if (list == true) {
-               mapiprofile_list(profdb);
+               mapiprofile_list(mapi_ctx, profdb);
        }
 
        if (dump == true) {
-               mapiprofile_dump(profdb, profname);
+               mapiprofile_dump(mapi_ctx, profdb, profname);
        }
 
        if (attribute) {
-               mapiprofile_attribute(profdb, profname, attribute);
+               mapiprofile_attribute(mapi_ctx, profdb, profname, attribute);
        }
 
 cleanup:
@@ -909,6 +846,8 @@ cleanup:
        free((void*)rename);
        free((void*)attribute);
 
+       if (mapi_ctx)
+               MAPIUninitialize(mapi_ctx);
        poptFreeContext(pc);
        talloc_free(mem_ctx);