From 856c8038870200dce91dd7e250c7097a2e0673f5 Mon Sep 17 00:00:00 2001 From: Patrick Simpson Date: Wed, 12 Apr 2017 11:53:09 +0200 Subject: [PATCH] [KOE-92] Turns out item Add and Change events pass a handle to a COM object that must be released. Changed the event handler to release it, with the global option ReleaseItemEventWrappers (default true) to revert back to old behaviour. --- .../AcaciaZPushPlugin/GlobalOptions.cs | 10 ++++++++++ .../OutlookWrappers/AppointmentItemWrapper.cs | 5 ++--- .../Stubs/OutlookWrappers/ItemsWrapper.cs | 18 ++++++------------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/GlobalOptions.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/GlobalOptions.cs index e413474..72d9fc4 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/GlobalOptions.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/GlobalOptions.cs @@ -127,6 +127,16 @@ namespace Acacia } private static readonly BoolOption HOOK_ITEM_EVENTS = new BoolOption("HookItemEvents", true); + [AcaciaOption("Enables or disables the release of wrappers for item events. " + + "This should normally be enabled, but can be disabled to debug exceptions.")] + virtual public bool ReleaseItemEventWrappers + { + get { return GetOption(null, RELEASE_ITEM_EVENT_WRAPPERS); } + set { SetOption(null, RELEASE_ITEM_EVENT_WRAPPERS, value); } + } + private static readonly BoolOption RELEASE_ITEM_EVENT_WRAPPERS = new BoolOption("ReleaseItemEventWrappers", true); + + #region UI Options [AcaciaOption("Completely enables or disables modifications to the Outlook UI." + diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AppointmentItemWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AppointmentItemWrapper.cs index 46ed301..e2a4fc7 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AppointmentItemWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AppointmentItemWrapper.cs @@ -108,10 +108,9 @@ namespace Acacia.Stubs.OutlookWrappers { get { - using (ComRelease com = new ComRelease()) + using (IBase parent = Mapping.Wrap(_item.Parent)) { - NSOutlook.Folder parent = com.Add(_item.Parent); - return parent?.EntryID; + return parent.EntryID; } } } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/ItemsWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/ItemsWrapper.cs index 79f81b4..de854f7 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/ItemsWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/ItemsWrapper.cs @@ -189,14 +189,11 @@ namespace Acacia.Stubs.OutlookWrappers { try { - if (_itemAdd != null) + using (IItem item = Mapping.Wrap(objItem, GlobalOptions.INSTANCE.ReleaseItemEventWrappers)) { - using (IItem item = Mapping.Wrap(objItem, false)) + if (item != null && _itemAdd != null) { - if (item != null) - { - _itemAdd(item); - } + _itemAdd(item); } } } @@ -239,14 +236,11 @@ namespace Acacia.Stubs.OutlookWrappers { try { - if (_itemChange != null) + using (IItem item = Mapping.Wrap(objItem, GlobalOptions.INSTANCE.ReleaseItemEventWrappers)) { - using (IItem item = Mapping.Wrap(objItem, false)) + if (item != null && _itemChange != null) { - if (item != null) - { - _itemChange(item); - } + _itemChange(item); } } }