Skip to content

Commit f1d2768

Browse files
authored
[Runtime] Fix swift_weakTakeStrong(). (#65857)
It turns out that when taking the last weak reference for an object that has been deallocated, we might have returned a non-null pointer when we shouldn't have. Which is exciting. rdar://106375185
1 parent 6c4331d commit f1d2768

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

stdlib/public/runtime/WeakReference.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ class WeakReference {
175175
HeapObject *nativeTakeStrongFromBits(WeakReferenceBits bits) {
176176
auto side = bits.getNativeOrNull();
177177
if (side) {
178+
auto obj = side->tryRetain();
178179
side->decrementWeak();
179-
return side->tryRetain();
180+
return obj;
180181
} else {
181182
return nullptr;
182183
}

0 commit comments

Comments
 (0)