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

chore(ios): add protection under unknown memory corruption #4172

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 10 additions & 4 deletions renderer/native/ios/renderer/HippyUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ - (__kindof HippyViewManager *)viewManagerForViewName:(NSString *)viewName {
#pragma mark Schedule Block

- (void)addUIBlock:(HippyViewManagerUIBlock)block {
HippyAssertNotMainQueue();
if (!block || !_viewRegistry) {
return;
}
Expand All @@ -754,6 +755,7 @@ - (void)addUIBlock:(HippyViewManagerUIBlock)block {
}

- (void)flushUIBlocksOnRootNode:(std::weak_ptr<RootNode>)rootNode {
HippyAssertNotMainQueue();
// First copy the previous blocks into a temporary variable, then reset the
// pending blocks to a new array. This guards against mutation while
// processing the pending blocks in another thread.
Expand All @@ -765,8 +767,8 @@ - (void)flushUIBlocksOnRootNode:(std::weak_ptr<RootNode>)rootNode {
TDF_PERF_DO_STMT_AND_LOG(unsigned int rand = arc4random(); , "flushUIBlocksOnRootNode(random id:%u", rand);

int32_t rootTag = strongRootNode->GetId();
NSArray<HippyViewManagerUIBlock> *previousPendingUIBlocks = _pendingUIBlocks;
_pendingUIBlocks = [NSMutableArray new];
NSArray<HippyViewManagerUIBlock> *previousPendingUIBlocks = [NSArray arrayWithArray:_pendingUIBlocks];
[_pendingUIBlocks removeAllObjects];
__weak __typeof(self)weakSelf = self;
if (previousPendingUIBlocks.count) {
// Execute the previously queued UI blocks
Expand All @@ -779,8 +781,12 @@ - (void)flushUIBlocksOnRootNode:(std::weak_ptr<RootNode>)rootNode {
@try {
// Note: viewRegistry may be modified in the block, and it may be stored internally as NSMapTable
// so to ensure that it is up-to-date, it can only be retrieved each time.
NSDictionary* viewReg = [strongSelf.viewRegistry componentsForRootTag:@(rootTag)];
block(strongSelf, viewReg);
// there is no need to do null protection under normal circumstances,
// but some app have such reports, just used as a protection in case of memory corruption.
if (block) {
NSDictionary* viewReg = [strongSelf.viewRegistry componentsForRootTag:@(rootTag)];
block(strongSelf, viewReg);
}
} @catch (NSException *exception) {
HippyLogError(@"Exception thrown while executing UI block: %@", exception);
}
Expand Down
Loading