Skip to content

Commit b18732e

Browse files
committed
Use unsafe_unretained when weak reference system not guaranteed by deployment target
1 parent 37dadc2 commit b18732e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

GCD/GCDAsyncSocket.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ typedef enum GCDAsyncSocketError GCDAsyncSocketError;
9797
uint32_t flags;
9898
uint16_t config;
9999

100+
#if __has_feature(objc_arc_weak)
100101
__weak id delegate;
102+
#else
103+
__unsafe_unretained id delegate;
104+
#endif
101105
dispatch_queue_t delegateQueue;
102106

103107
int socket4FD;

GCD/GCDAsyncSocket.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ - (BOOL)doAccept:(int)parentSocketFD
15951595

15961596
// Create GCDAsyncSocket instance for accepted socket
15971597

1598-
GCDAsyncSocket *acceptedSocket = [[GCDAsyncSocket alloc] initWithDelegate:delegate
1598+
GCDAsyncSocket *acceptedSocket = [[GCDAsyncSocket alloc] initWithDelegate:theDelegate
15991599
delegateQueue:delegateQueue
16001600
socketQueue:childSocketQueue];
16011601

@@ -4766,7 +4766,7 @@ - (void)completeCurrentRead
47664766
if (delegateQueue && [delegate respondsToSelector:@selector(socket:didReadData:withTag:)])
47674767
{
47684768
__strong id theDelegate = delegate;
4769-
GCDAsyncReadPacket *theRead = currentRead;
4769+
GCDAsyncReadPacket *theRead = currentRead; // Ensure currentRead retained since result may not own buffer
47704770

47714771
dispatch_async(delegateQueue, ^{ @autoreleasepool {
47724772

0 commit comments

Comments
 (0)