fix leaking realm
This commit is contained in:
parent
7a6141e066
commit
76c2d3cd54
|
@ -297,11 +297,26 @@ void Realm<T>::constructor(ContextType ctx, ObjectType this_object, size_t argc,
|
|||
if (!Value::is_undefined(ctx, migration_value)) {
|
||||
FunctionType migration_function = Value::validated_to_function(ctx, migration_value, "migration");
|
||||
config.migration_function = [=](SharedRealm old_realm, SharedRealm realm) {
|
||||
auto old_realm_ptr = new SharedRealm(old_realm);
|
||||
auto realm_ptr = new SharedRealm(realm);
|
||||
ValueType arguments[2] = {
|
||||
create_object<T, RealmClass<T>>(ctx, new SharedRealm(old_realm)),
|
||||
create_object<T, RealmClass<T>>(ctx, new SharedRealm(realm))
|
||||
create_object<T, RealmClass<T>>(ctx, old_realm_ptr),
|
||||
create_object<T, RealmClass<T>>(ctx, realm_ptr)
|
||||
};
|
||||
|
||||
try {
|
||||
Function<T>::call(ctx, migration_function, 2, arguments);
|
||||
}
|
||||
catch (...) {
|
||||
old_realm->close();
|
||||
old_realm_ptr->reset();
|
||||
realm_ptr->reset();
|
||||
throw;
|
||||
}
|
||||
|
||||
old_realm->close();
|
||||
old_realm_ptr->reset();
|
||||
realm_ptr->reset();
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ WeakRealmNotifier::WeakRealmNotifier(const std::shared_ptr<Realm>& realm, bool c
|
|||
};
|
||||
|
||||
CFRunLoopSourceContext ctx{};
|
||||
ctx.info = new RefCountedWeakPointer{realm, {1}};
|
||||
ctx.info = new RefCountedWeakPointer{realm, {0}};
|
||||
ctx.perform = [](void* info) {
|
||||
if (auto realm = static_cast<RefCountedWeakPointer*>(info)->realm.lock()) {
|
||||
realm->notify();
|
||||
|
|
|
@ -247,6 +247,7 @@ void Realm::update_schema(std::unique_ptr<Schema> schema, uint64_t version)
|
|||
if (m_config.migration_function) {
|
||||
m_config.migration_function(old_realm, shared_from_this());
|
||||
}
|
||||
m_config.migration_function = nullptr;
|
||||
};
|
||||
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue