Skip to content

Commit

Permalink
Fix double free-ing the gchandle
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev committed Aug 20, 2019
1 parent ceea801 commit f862bb7
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions Realm/Realm/Handles/SharedRealmHandleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,15 @@ public static async Task<SharedRealmHandle> OpenWithSyncAsync(Configuration conf

var tcs = new TaskCompletionSource<IntPtr>();
var tcsHandle = GCHandle.Alloc(tcs);
try
{
var asyncTaskHandle = NativeMethods.open_with_sync_async(configuration, syncConfiguration, marshaledSchema.Objects, marshaledSchema.Objects.Length, marshaledSchema.Properties, encryptionKey, GCHandle.ToIntPtr(tcsHandle), out var nativeException);
// TODO: convert asyncTaskHandle to something meaningful.
nativeException.ThrowIfNecessary();
var asyncTaskHandle = NativeMethods.open_with_sync_async(configuration, syncConfiguration, marshaledSchema.Objects, marshaledSchema.Objects.Length, marshaledSchema.Properties, encryptionKey, GCHandle.ToIntPtr(tcsHandle), out var nativeException);
// TODO: convert asyncTaskHandle to something meaningful.
nativeException.ThrowIfNecessary();

var referenceHandle = await tcs.Task;
var referenceHandle = await tcs.Task;

// TODO: investigate why converting to ThreadSafeReference handle fails on destroy
var realmPtr = SharedRealmHandle.ResolveFromReference(referenceHandle);
return new SharedRealmHandle(realmPtr);
}
finally
{
tcsHandle.Free();
}
// TODO: investigate why converting to ThreadSafeReference handle fails on destroy
var realmPtr = SharedRealmHandle.ResolveFromReference(referenceHandle);
return new SharedRealmHandle(realmPtr);
}

public static string GetRealmPath(User user, Uri serverUri)
Expand Down

0 comments on commit f862bb7

Please sign in to comment.