Skip to content

Commit 8db4b9f

Browse files
authored
Merge pull request #65776 from mikeash/dealloc-partial-class-instance-setclass-readonly
[Runtime] Immediate release and return when destroying partial instance of pure ObjC class.
2 parents d7e18cb + 3a396af commit 8db4b9f

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
@@ -854,6 +854,17 @@ void swift::swift_deallocPartialClassInstance(HeapObject *object,
854854
// Destroy ivars
855855
auto *classMetadata = _swift_getClassOfAllocated(object)->getClassObject();
856856
assert(classMetadata && "Not a class?");
857+
858+
#if SWIFT_OBJC_INTEROP
859+
// If the object's class is already pure ObjC class, just release it and move
860+
// on. There are no ivar destroyers. This avoids attempting to mutate
861+
// placeholder objects statically created in read-only memory.
862+
if (classMetadata->isPureObjC()) {
863+
objc_release((id)object);
864+
return;
865+
}
866+
#endif
867+
857868
while (classMetadata != metadata) {
858869
#if SWIFT_OBJC_INTEROP
859870
// If we have hit a pure Objective-C class, we won't see another ivar

0 commit comments

Comments
 (0)