mirror of
https://github.com/Kopano-dev/kopano-ol-extension.git
synced 2023-10-10 13:37:40 +02:00
[KOE-176] Possible fix for memory issue
This commit is contained in:
parent
140611b461
commit
d85c3ae19d
@ -396,6 +396,7 @@
|
|||||||
<Compile Include="Utils\DisposableTracerFull.cs" />
|
<Compile Include="Utils\DisposableTracerFull.cs" />
|
||||||
<Compile Include="Utils\DisposableWrapper.cs" />
|
<Compile Include="Utils\DisposableWrapper.cs" />
|
||||||
<Compile Include="Utils\ImageUtils.cs" />
|
<Compile Include="Utils\ImageUtils.cs" />
|
||||||
|
<Compile Include="Utils\MemUtil.cs" />
|
||||||
<Compile Include="Utils\RegistryUtil.cs" />
|
<Compile Include="Utils\RegistryUtil.cs" />
|
||||||
<Compile Include="Utils\SizeUtil.cs" />
|
<Compile Include="Utils\SizeUtil.cs" />
|
||||||
<Compile Include="ZPush\API\SharedFolders\AvailableFolder.cs" />
|
<Compile Include="ZPush\API\SharedFolders\AvailableFolder.cs" />
|
||||||
|
@ -134,8 +134,8 @@ namespace Acacia.Features.Signatures
|
|||||||
if (serverSignatureHash != null)
|
if (serverSignatureHash != null)
|
||||||
{
|
{
|
||||||
Logger.Instance.Trace(this, "Checking signature hash for account {0}: {1}", account, serverSignatureHash);
|
Logger.Instance.Trace(this, "Checking signature hash for account {0}: {1}", account, serverSignatureHash);
|
||||||
if (serverSignatureHash == account.LocalSignaturesHash)
|
//if (serverSignatureHash == account.LocalSignaturesHash)
|
||||||
return;
|
// return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch signatures if there is a change
|
// Fetch signatures if there is a change
|
||||||
|
@ -246,16 +246,16 @@ namespace Acacia.Stubs.OutlookWrappers
|
|||||||
{
|
{
|
||||||
case PropType.UNICODE:
|
case PropType.UNICODE:
|
||||||
Logger.Instance.Trace(this, "SetAccountProp5: {0}: {1}", propTag, value);
|
Logger.Instance.Trace(this, "SetAccountProp5: {0}: {1}", propTag, value);
|
||||||
fixed (char* ptr = ((string)value).ToCharArray())
|
using (MapiAlloc mem = MapiAlloc.FromString((string)value))
|
||||||
{
|
{
|
||||||
ACCT_VARIANT val = new ACCT_VARIANT()
|
ACCT_VARIANT val = new ACCT_VARIANT()
|
||||||
{
|
{
|
||||||
dwType = (uint)PropType.UNICODE,
|
dwType = (uint)PropType.UNICODE,
|
||||||
lpszW = ptr
|
lpszW = (char*)mem.Ptr
|
||||||
};
|
};
|
||||||
//olk.SetProp(propTag, &val);
|
olk.SetProp(propTag, &val);
|
||||||
Logger.Instance.Trace(this, "SetAccountProp6: {0}: {1}", propTag, value);
|
Logger.Instance.Trace(this, "SetAccountProp6: {0}: {1}", propTag, value);
|
||||||
//olk.SaveChanges(0);
|
olk.SaveChanges(0);
|
||||||
Logger.Instance.Trace(this, "SetAccountProp7: {0}: {1}", propTag, value);
|
Logger.Instance.Trace(this, "SetAccountProp7: {0}: {1}", propTag, value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -267,9 +267,9 @@ namespace Acacia.Stubs.OutlookWrappers
|
|||||||
dwType = (uint)PropType.LONG,
|
dwType = (uint)PropType.LONG,
|
||||||
dw = (uint)value
|
dw = (uint)value
|
||||||
};
|
};
|
||||||
//olk.SetProp(propTag, &val);
|
olk.SetProp(propTag, &val);
|
||||||
Logger.Instance.Trace(this, "SetAccountProp9: {0}: {1}", propTag, value);
|
Logger.Instance.Trace(this, "SetAccountProp9: {0}: {1}", propTag, value);
|
||||||
//olk.SaveChanges(0);
|
olk.SaveChanges(0);
|
||||||
Logger.Instance.Trace(this, "SetAccountPropA: {0}: {1}", propTag, value);
|
Logger.Instance.Trace(this, "SetAccountPropA: {0}: {1}", propTag, value);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
51
src/AcaciaZPushPlugin/AcaciaZPushPlugin/Utils/MemUtil.cs
Normal file
51
src/AcaciaZPushPlugin/AcaciaZPushPlugin/Utils/MemUtil.cs
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
using Acacia.Native;
|
||||||
|
using Acacia.Native.MAPI;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Acacia.Utils
|
||||||
|
{
|
||||||
|
public class MapiAlloc : IDisposable
|
||||||
|
{
|
||||||
|
public IntPtr Ptr { get; private set; }
|
||||||
|
|
||||||
|
private MapiAlloc(IntPtr ptr)
|
||||||
|
{
|
||||||
|
this.Ptr = ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
MAPI.MAPIFreeBuffer(Ptr);
|
||||||
|
Ptr = IntPtr.Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MapiAlloc FromString(string value, Encoding encoding = null)
|
||||||
|
{
|
||||||
|
if (encoding == null)
|
||||||
|
encoding = Encoding.Unicode;
|
||||||
|
|
||||||
|
byte[] data = encoding.GetBytes(value);
|
||||||
|
byte[] term = encoding.GetBytes(new char[] { (char)0 });
|
||||||
|
|
||||||
|
// Allocate the buffer
|
||||||
|
int size = data.Length + term.Length;
|
||||||
|
IntPtr ptr = IntPtr.Zero;
|
||||||
|
IntPtr res = MAPI.MAPIAllocateBuffer((uint)size, ref ptr);
|
||||||
|
if (res != IntPtr.Zero)
|
||||||
|
throw new InvalidOperationException("MAPI Allocation failed: " + res);
|
||||||
|
|
||||||
|
// Zero it
|
||||||
|
Kernel32.ZeroMemory(ptr, size);
|
||||||
|
|
||||||
|
// And copy the data
|
||||||
|
Marshal.Copy(data, 0, ptr, data.Length);
|
||||||
|
|
||||||
|
return new MapiAlloc(ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user