Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an NRE in session property changed callback #3061

Merged
merged 2 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* None

### Fixed
* None
* Fixed a NullReferenceException being thrown when subscribing to `PropertyChanged` notifications on a `Session` instance that is then garbage collected prior to unsubscribing. (PR [#3061](https://github.com/realm/realm-dotnet/pull/3061))

### Compatibility
* Realm Studio: 11.0.0 or later.

### Internal
* Using Core x.y.z.
* Using Core 12.9.0.

## 10.17.0 (2022-10-06)

Expand Down
5 changes: 5 additions & 0 deletions Realm/Realm/Handles/SessionHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ private static void HandleSessionPropertyChangedCallback(IntPtr managedSessionHa
_ => throw new NotSupportedException($"Unexpected notifiable property value: {property}")
};
var session = (Session)GCHandle.FromIntPtr(managedSessionHandle).Target;
if (session == null)
{
// We're taking a weak handle to the session, so it's possible that it's been collected
return;
}

System.Threading.ThreadPool.QueueUserWorkItem(_ =>
{
Expand Down