From 4e294d2aa389f1936b919c0249001f421e49e605 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Wed, 1 Aug 2018 15:26:02 -0700 Subject: [PATCH] Make strong reference in notification center callback --- src/objective-c/GRPCClient/GRPCCall.m | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m index 387a88dc177..3c4e87cf5a9 100644 --- a/src/objective-c/GRPCClient/GRPCCall.m +++ b/src/objective-c/GRPCClient/GRPCCall.m @@ -531,12 +531,15 @@ static NSString *const kBearerPrefix = @"Bearer "; - (void)connectivityChanged:(NSNotification *)note { // Cancel underlying call upon this notification - [self cancelCall]; - [self maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain - code:GRPCErrorCodeUnavailable - userInfo:@{ - NSLocalizedDescriptionKey : @"Connectivity lost." - }]]; + __strong GRPCCall *strongSelf = self; + if (strongSelf) { + [self cancelCall]; + [self maybeFinishWithError:[NSError errorWithDomain:kGRPCErrorDomain + code:GRPCErrorCodeUnavailable + userInfo:@{ + NSLocalizedDescriptionKey : @"Connectivity lost." + }]]; + } } @end