From 2237ea6d2e38376da6bb065128f6790412325b1b Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 23 Dec 2019 07:44:22 -0800 Subject: [PATCH] Fabric: Fixed crash in RCTGenericDelegateSplitter (collection was mutated while being enumerated) Summary: The concept of the class cannot guarantee that the set of delegates cannot be removed as a side-effect of calling a delegate, so we must make a copy of the delegates before calling on them. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D19213549 fbshipit-source-id: 7040b2994433d83e3148ec73820e051729be9e29 --- React/Fabric/Utils/RCTGenericDelegateSplitter.mm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/React/Fabric/Utils/RCTGenericDelegateSplitter.mm b/React/Fabric/Utils/RCTGenericDelegateSplitter.mm index 38b183daaba..7a7e109fb11 100644 --- a/React/Fabric/Utils/RCTGenericDelegateSplitter.mm +++ b/React/Fabric/Utils/RCTGenericDelegateSplitter.mm @@ -78,11 +78,17 @@ - (void)forwardInvocation:(NSInvocation *)invocation { + NSMutableArray *targets = [[NSMutableArray alloc] initWithCapacity:_delegates.count]; + for (id delegate in _delegates) { if ([delegate respondsToSelector:[invocation selector]]) { - [invocation invokeWithTarget:delegate]; + [targets addObject:delegate]; } } + + for (id target in targets) { + [invocation invokeWithTarget:target]; + } } @end