From b49f2f594bdfb7bea2819ca4bcd5221038177708 Mon Sep 17 00:00:00 2001 From: Kenneth Geisshirt Date: Thu, 22 Nov 2018 16:12:58 +0100 Subject: [PATCH] Protect the context from being GCed (#2127) * Protect the context from being GCed --- CHANGELOG.md | 1 + src/js_realm.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5faffbbd..de54755a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ x.x.x Release notes (yyyy-MM-dd) * Prevent automatic token refreshes for Realms that have been closed. Previously, these could have resulted in obscure `Unhandled session token refresh error` messages in the logs that were benign. ([#2119](https://github.com/realm/realm-js/pull/2119)) * When trying to debug, users could experience a crash with the message `this._constructor is not a function`. (https://github.com/realm/realm-js/issues/491#issuecomment-438688937, since v2.19.0-rc.4) * Check the correct name when automatically adding the permission object schemas to the schema for query-based sync realms so that defining types with the same name works correctly. ([#2121](https://github.com/realm/realm-js/pull/2121), since 2.15.0) +* Fixes a bug where the JS engine might garbage collect an object prematurely leading to a native crash. ([#496](https://github.com/realm/realm-js-private/issues/496), since v2.19.0) ### Compatibility * Realm Object Server: 3.11.0 or later. diff --git a/src/js_realm.hpp b/src/js_realm.hpp index 69520807..058574d9 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -890,7 +890,7 @@ void RealmClass::async_open_realm(ContextType ctx, ObjectType this_object, Ar realm->close(); // Reopen it with the real configuration and pass that Realm back to the callback - auto final_realm = create_shared_realm(ctx, std::move(config), + auto final_realm = create_shared_realm(protected_ctx, std::move(config), schema_updated, std::move(defaults), std::move(constructors)); ObjectType object = create_object>(protected_ctx, new SharedRealm(final_realm));