Skip to content

Commit 94e1379

Browse files
authored
Merge pull request #65822 from mikeash/dealloc-partial-class-instance-setclass-readonly-5.9
[5.9][Runtime] Immediate release and return when destroying partial instance of pure ObjC class.
2 parents fd027ae + 4ba8819 commit 94e1379

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

stdlib/public/runtime/HeapObject.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,17 @@ void swift::swift_deallocPartialClassInstance(HeapObject *object,
849849
// Destroy ivars
850850
auto *classMetadata = _swift_getClassOfAllocated(object)->getClassObject();
851851
assert(classMetadata && "Not a class?");
852+
853+
#if SWIFT_OBJC_INTEROP
854+
// If the object's class is already pure ObjC class, just release it and move
855+
// on. There are no ivar destroyers. This avoids attempting to mutate
856+
// placeholder objects statically created in read-only memory.
857+
if (classMetadata->isPureObjC()) {
858+
objc_release((id)object);
859+
return;
860+
}
861+
#endif
862+
852863
while (classMetadata != metadata) {
853864
#if SWIFT_OBJC_INTEROP
854865
// If we have hit a pure Objective-C class, we won't see another ivar

0 commit comments

Comments
 (0)