Skip to content

Commit

Permalink
Fix test errors on string copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Muxi Yan committed Jan 17, 2017
1 parent a36bdc1 commit d3c2594
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/objective-c/GRPCClient/private/GRPCWrappedCall.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,15 @@ - (instancetype) initWithHandler:(void (^)(NSError *, NSDictionary *))handler {
__weak typeof(self) weakSelf = self;
_handler = ^{
__strong typeof(self) strongSelf = weakSelf;
NSError *error = [NSError grpc_errorFromStatusCode:strongSelf->_statusCode
details:(char*)GRPC_SLICE_START_PTR(strongSelf->_details)];
NSDictionary *trailers = [NSDictionary
grpc_dictionaryFromMetadataArray:strongSelf->_trailers];
handler(error, trailers);
if (strongSelf) {
char *details = grpc_slice_to_c_string(strongSelf->_details);
NSError *error = [NSError grpc_errorFromStatusCode:strongSelf->_statusCode
details:details];
NSDictionary *trailers = [NSDictionary
grpc_dictionaryFromMetadataArray:strongSelf->_trailers];
handler(error, trailers);
gpr_free(details);
}
};
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/objective-c/GRPCClient/private/NSDictionary+GRPC.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ + (instancetype)grpc_dictionaryFromMetadataArray:(grpc_metadata_array)array {
+ (instancetype)grpc_dictionaryFromMetadata:(grpc_metadata *)entries count:(size_t)count {
NSMutableDictionary *metadata = [NSMutableDictionary dictionaryWithCapacity:count];
for (grpc_metadata *entry = entries; entry < entries + count; entry++) {
NSString *name = [NSString stringWithCString:(char*)GRPC_SLICE_START_PTR(entry->key)
char *key = grpc_slice_to_c_string(entry->key);
NSString *name = [NSString stringWithCString:key
encoding:NSASCIIStringEncoding];
gpr_free(key);
if (!name || metadata[name]) {
// Log if name is nil?
continue;
Expand Down

0 comments on commit d3c2594

Please sign in to comment.