From 21f512eddf243b05f650431b942758b38582b518 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Mon, 3 Jun 2019 11:22:30 -0700 Subject: [PATCH] Make a copy of received headers --- src/objective-c/GRPCClient/GRPCCall.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m index 71b03f15f17..5a3440f84ed 100644 --- a/src/objective-c/GRPCClient/GRPCCall.m +++ b/src/objective-c/GRPCClient/GRPCCall.m @@ -714,7 +714,12 @@ const char *kCFStreamVarName = "grpc_cfstream"; __strong GRPCCall *strongSelf = weakSelf; if (strongSelf) { @synchronized(strongSelf) { - strongSelf.responseHeaders = headers; + // it is ok to set nil because headers are only received once + strongSelf.responseHeaders = nil; + // copy the header so that the GRPCOpRecvMetadata object may be dealloc'ed + NSDictionary *copiedHeaders = [[NSDictionary alloc] initWithDictionary:headers + copyItems:YES]; + strongSelf.responseHeaders = copiedHeaders; strongSelf->_pendingCoreRead = NO; [strongSelf maybeStartNextRead]; }