Commit 85cbf91
Fix residual EXC_BREAKPOINT crashes in FBObjectiveCObject.allRetainedObjects
Summary:
After D103430527 reduced the EXC_BREAKPOINT crashes by ~95% in alpha/beta builds on Instagram and Threads/Barcelona, two residual crash modes still appear in alpha/beta at low rates (no production exposure yet):
1. swift_unknownObjectRetain crash inside the objc bridge of SwiftIntrospector.getPropertyValue. The Mirror API can return stale pointers for unowned references whose target was deallocated between the property assignment and the RCD traversal. The previous fix filtered out value types, but stale class instance pointers still passed through.
2. _class_lookUpIvar / object_getIvar crash when the parent object is released by another thread mid-traversal. The detector previously used objectPtr (a raw void*) which doesn't keep the object alive across the method.
Fixes:
- SwiftIntrospector.swift: Add isLikelyLiveObject() validation using malloc_size to filter out dangling pointers. Tagged pointers (high bit on arm64, low bit on x86_64) are handled separately since they aren't heap-allocated. Class instances and Foundation-bridgeable values are now liveness-checked before bridging to ObjC id.
- FBObjectiveCObject.m: Pin the object alive for the entire allRetainedObjects method via a strong local. For ObjC objects, reading self.object via the weak property gives us a brief strong reference. For pure Swift objects, the FBSwiftStrongRef wrapper held by the candidates array continues to keep the object alive.
Both crash signatures observed in alpha/beta builds:
- Instagram T268028126 (instagram_ios_crashes:69bd7a32c0a579e93bee27efe143c89a)
- Threads T268462327 (barcelona_ios_crashes:0132b4a00a546d59009ed4420a32303b)
Sample stack 1 (swift_unknownObjectRetain):
swift_unknownObjectRetain
objc static SwiftIntrospector.getPropertyValue(object:name:)
-[FBObjectiveCObject allRetainedObjects]
-[FBNodeEnumerator nextObject]
-[FBRetainCycleDetector _findRetainCyclesInObject:stackDepth:]
Sample stack 2 (object_getIvar):
_class_lookUpIvar
object_getIvar
-[FBObjectiveCObject allRetainedObjects]
-[FBNodeEnumerator nextObject]
-[FBRetainCycleDetector _findRetainCyclesInObject:stackDepth:]
This is a preventive fix to ensure the residual crashes do not leak into production.
Reviewed By: thegreatwallfb
Differential Revision: D104141469
fbshipit-source-id: 66fd98e5e360a7fca10fe8e9f89fba7834f9b5101 parent 59857ae commit 85cbf91
2 files changed
Lines changed: 43 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | | - | |
24 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
25 | 38 | | |
26 | 39 | | |
27 | 40 | | |
| |||
Lines changed: 27 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
47 | 52 | | |
48 | | - | |
| 53 | + | |
| 54 | + | |
49 | 55 | | |
50 | 56 | | |
51 | 57 | | |
| |||
57 | 63 | | |
58 | 64 | | |
59 | 65 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | 66 | | |
64 | | - | |
| 67 | + | |
| 68 | + | |
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
68 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
69 | 90 | | |
70 | 91 | | |
71 | 92 | | |
| |||
0 commit comments