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 a crash that may occur when resolving a thread-safe reference #8722

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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: 4 additions & 0 deletions Realm/RLMError.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ typedef RLM_ERROR_ENUM(NSInteger, RLMError, RLMErrorDomain) {
subscription or the server will reject the write.
*/
RLMErrorNoSubscriptionForWrite = 22,
/ **
Denotes an error that occurs when resolving thread safe reference returns a nil object.
*/
RLMErrorObjectNotFound = 23
};

#pragma mark - RLMSyncError
Expand Down
7 changes: 7 additions & 0 deletions Realm/RLMObjectBase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,13 @@ - (void)addNotificationBlock:(RLMObjectNotificationCallback)block
return;
}
RLMObjectBase *obj = [_realm resolveThreadSafeReference:tsr];
if (!obj) {
error = [NSError errorWithDomain:RLMAppErrorDomain
code:RLMErrorObjectNotFound
userInfo:nil];
block(nil, nil, nil, nil, error);
return;
}

_object = realm::Object(_realm->_realm, *obj->_info->objectSchema, obj->_row);
_token = _object.add_notification_callback(ObjectChangeCallbackWrapper{block, obj},
Expand Down