-
Notifications
You must be signed in to change notification settings - Fork 6k
fix crash SemanticsObject dealloc and access the children #27786
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
It is not safe to call method on an object for which dealloc has been called, so this is a bug; niling the ivar is papering over the issue; the correct fix would be to ensure that this call doesn't happen in the first place. |
I wonder if this reproduces if the |
@xiaoxiaowesley Can you try this? Were you able to reproduce? |
Sorry I can't reproduce.But I received many crash cases from my user. |
@jmagman I added test but the "needs tests" label still there. Does the code and test look good to you? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a complete workaround for the UIKit dealloc bug. You've added a guard at the spot where it's crashing, but not in the other places self.children
is called. And we don't know and can't rely on their dealloc
implementation.
It's unusual, but what if we waited to dealloc _children
and _platformViewSemanticsContainer
until after [super dealloc]
?
- (void)dealloc {
for (SemanticsObject* child in _children) {
[child privateSetParent:nil];
}
[_children removeAllObjects];
_parent = nil;
_container.get().semanticsObject = nil;
[super dealloc];
// Due to a bug in -[UIAccessibilityElementSuperCategory dealloc]
// that calls into self.children, delay releasing ivars until after `[super dealloc]`.
[_children release];
[_platformViewSemanticsContainer release];
}
@stuartmorgan can you foresee any problems with this?
I looked at this a bit more. |
In apple's documentation UIAccessibilityElement.h said:
Since SemanticsObject which is the subclass of UIAccessibilityElement maintain its own data structure like children and container in its own life cycle. So it must be release all the properties before call |
Why? Do you have evidence that anything other than |
Of course I not sure if other override function been called during Setting all properies to nil is a way and using an @stuartmorgan I add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should make sure all the properties(children or container) is nil before
[super dealloc]
called.Why? Do you have evidence that anything other than
accessibilityContainer
is improperly called during[super dealloc]
?
I spent all day yesterday yak shaving trying to get the engine tests to run on iOS 9 to see what else-dealloc
could be calling. My macOS is too new to run an iOS 9 simulator, and I actually have a 9.3.6 iPhone 4s but I can't run the engine unit tests on a physical device. flutter/flutter#87699
This is as good a hack as any. We can see if any new crashes surface. LGTM
Co-authored-by: Jenn Magder <[email protected]>
shell/platform/darwin/ios/framework/Source/SemanticsObjectTest.mm
Outdated
Show resolved
Hide resolved
Co-authored-by: Jenn Magder <[email protected]>
…utter#27786)" This reverts commit 2909407.
I found a crash in SemanticsObject.mm when
[SemanticsObject dealloc]
and access propertyself.children
but the
children
has called releaseHere is the crash logic:
[_children release]
first called in[SemanticsObject dealloc]
but _children not to set nil[super dealloc]
will access[UIAccessibilityElementSuperCategory dealloc]
and then[SemanticsObject accessibilityContainer]
and access the released_children
property, and crash finallyAnd the issue is here flutter/flutter#87247
flutter/flutter#66032