[KOE-176] Possible fix for memory issue

This commit is contained in:
Patrick Simpson 2018-09-26 13:08:46 +03:00
parent 140611b461
commit d85c3ae19d
4 changed files with 60 additions and 8 deletions

View File

@ -396,6 +396,7 @@
<Compile Include="Utils\DisposableTracerFull.cs" />
<Compile Include="Utils\DisposableWrapper.cs" />
<Compile Include="Utils\ImageUtils.cs" />
<Compile Include="Utils\MemUtil.cs" />
<Compile Include="Utils\RegistryUtil.cs" />
<Compile Include="Utils\SizeUtil.cs" />
<Compile Include="ZPush\API\SharedFolders\AvailableFolder.cs" />

View File

@ -134,8 +134,8 @@ namespace Acacia.Features.Signatures
if (serverSignatureHash != null)
{
Logger.Instance.Trace(this, "Checking signature hash for account {0}: {1}", account, serverSignatureHash);
if (serverSignatureHash == account.LocalSignaturesHash)
return;
//if (serverSignatureHash == account.LocalSignaturesHash)
// return;
}
// Fetch signatures if there is a change

View File

@ -246,16 +246,16 @@ namespace Acacia.Stubs.OutlookWrappers
{
case PropType.UNICODE:
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()
{
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);
//olk.SaveChanges(0);
olk.SaveChanges(0);
Logger.Instance.Trace(this, "SetAccountProp7: {0}: {1}", propTag, value);
}
break;
@ -267,9 +267,9 @@ namespace Acacia.Stubs.OutlookWrappers
dwType = (uint)PropType.LONG,
dw = (uint)value
};
//olk.SetProp(propTag, &val);
olk.SetProp(propTag, &val);
Logger.Instance.Trace(this, "SetAccountProp9: {0}: {1}", propTag, value);
//olk.SaveChanges(0);
olk.SaveChanges(0);
Logger.Instance.Trace(this, "SetAccountPropA: {0}: {1}", propTag, value);
break;
}

View 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);
}
}
}