From 2deda01e5c70dbaccb4b2761d7197ee11f736697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20J=2E=20Hern=C3=A1ndez=20Blasco?= Date: Wed, 2 Dec 2015 16:06:31 +0100 Subject: [PATCH] oc-mail: Do not crash after reconnect sending mails After the providing the workaround on rebuilding the LDAP connection, the sam_ctx variable can be freed and it was used as memory context to store the AddressBookEntryId or OneOffEntryId when resolving recipients. After this changeset, a local memory context which I think is more sane. --- OpenChange/MAPIStoreMailVolatileMessage.m | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/OpenChange/MAPIStoreMailVolatileMessage.m b/OpenChange/MAPIStoreMailVolatileMessage.m index 537a88854..90e459244 100644 --- a/OpenChange/MAPIStoreMailVolatileMessage.m +++ b/OpenChange/MAPIStoreMailVolatileMessage.m @@ -679,6 +679,14 @@ FillMessageHeadersFromProperties (NGMutableHashMap *headers, if (!fromResolved) { + TALLOC_CTX *local_mem_ctx; + local_mem_ctx = talloc_new(NULL); + if (!local_mem_ctx) + { + NSLog (@"%s: Out of memory", __PRETTY_FUNCTION__); + return; + } + NSLog (@"Message without an orig from, try to guess it from PidTagSenderEntryId"); senderEntryId = [mailProperties objectForKey: MAPIPropertyKey (PR_SENDER_ENTRYID)]; if (senderEntryId) @@ -692,7 +700,7 @@ FillMessageHeadersFromProperties (NGMutableHashMap *headers, bin32.cb = [senderEntryId length]; bin32.lpb = (uint8_t *) [senderEntryId bytes]; - addrBookEntryId = get_AddressBookEntryId (connInfo->sam_ctx, &bin32); + addrBookEntryId = get_AddressBookEntryId (local_mem_ctx, &bin32); if (addrBookEntryId && [[NSString stringWithGUID: &addrBookEntryId->ProviderUID] hasSuffix: @"08002b2fe182"]) { @@ -718,7 +726,7 @@ FillMessageHeadersFromProperties (NGMutableHashMap *headers, /* Try with One-Off EntryId */ struct OneOffEntryId *oneOffEntryId; - oneOffEntryId = get_OneOffEntryId (connInfo->sam_ctx, &bin32); + oneOffEntryId = get_OneOffEntryId (local_mem_ctx, &bin32); if (oneOffEntryId && [[NSString stringWithGUID: &oneOffEntryId->ProviderUID] hasSuffix: @"00dd010f5402"]) { @@ -727,9 +735,7 @@ FillMessageHeadersFromProperties (NGMutableHashMap *headers, [fromRecipient setObject: [NSString stringWithUTF8String: oneOffEntryId->EmailAddress.lpszW] forKey: @"email"]; } - talloc_free (oneOffEntryId); } - talloc_free (addrBookEntryId); if ([[fromRecipient allKeys] count] > 0) { @@ -739,6 +745,8 @@ FillMessageHeadersFromProperties (NGMutableHashMap *headers, } } + /* Free entryId */ + talloc_free(local_mem_ctx); } if (!recipients)